Reputation: 1758
Is the directory of findstr
always C:\Windows\system32\
for all OS from Windows XP to server 2012?
Or in other words is it safe to replace the following expression in a windows batch file:
findstr
to
C:\Windows\system32\findstr
Upvotes: 3
Views: 5606
Reputation: 49097
Extra information just for completeness.
Environment variable windir exists since Windows 95 and contains the path to Windows directory independent on which drive it is located and which name it has.
For NT based Windows (NT4, Windows 2000, Windows XP, Vista, Windows 7 / 8 / 8.1) there is additionally the environment variable SystemRoot which contains also the path to Windows directory as this is the parent directory for the system directories
For details about file system redirection read the File System Redirector page of Microsoft.
It is not only safe to use either
%windir%\System32\findstr.exe
or
%SystemRoot%\System32\findstr.exe
I would highly recommend using always one of those two strings in batch files as then it does not depend which folders are in environment variable PATH and which file extensions in environment variable PATHEXT.
There are some bad installers which add the folder path of the installed application to system environment variable PATH at beginning instead of appending at end and contain in the application's folder also find.exe
or findstr.exe
which are portings from Unix and therefore work completely different than find.exe
and findstr.exe
of Windows. AVRStudio is (or perhaps was as not verified with latest version of AVRStudio) an example breaking batch files of IT administrators not using always complete file name for Windows commands after installation.
Upvotes: 3
Reputation: 67216
I am afraid I don't understand the purpose of your question, so I rephrase it in a slightly different way.
If you type findstr
in a computer and the FINDSTR command run, then you may know the location of such findstr command this way:
for %%a in (findstr.exe) do echo %%~$PATH:a
So you may replace the following expression:
findstr
... by the next two lines:
for %%a in (findstr.exe) do set "findstrPath=%~$PATH:a"
%findstrPath%
... in a Windows Batch file and you will get exactly the same result.
So, the question arises: if you get the same result in both cases, why do you want to use the second, more complicated one?
Note also that the same point apply with any other external command like find
, xcopy
, forfiles
, etc. Why findstr
would be special in this point?
As I said before, I don't understand the purpose of your question...
Upvotes: 0
Reputation: 57262
Rather %windir%\system32\findstr.exe
as its possible windows to be installed on different than C:\
drive.
Upvotes: 2