Reputation: 413
I am running the windows command findstr to search for a specific sting only in .ini
files. The command I am running is findstr /i /s /m /C:\output *.ini
looking for the string \output
. The following is the output from the command
etc\billdirfile.ini
etc\doc1dirfile.ini
etc\ENVIRON.INI_20150902_0944
etc\ENVIRON.INI_20150903_1035
I expect a file etc\environ.ini
to show up in that list but it does not. When I rerun the command with an added wildcard at the end findstr /i /s /m /C:\output *.ini*
my out put is as follows.
etc\billdirfile.ini
etc\doc1dirfile.ini
etc\ENVIRON.INI
etc\ENVIRON.INI.bak
etc\ENVIRON.INI_20150901_1021
etc\ENVIRON.INI_20150901_1050
etc\ENVIRON.INI_20150901_1431
etc\ENVIRON.INI_20150901_1433
etc\ENVIRON.INI_20150901_1438
etc\ENVIRON.INI_20150902_0944
etc\ENVIRON.INI_20150902_0954
etc\ENVIRON.INI_20150903_1035
etc\ENVIRON.INI_20150903_1042
etc\ENVIRON.INI_20150903_1344
etc\ENVIRON.INI_20150922_1305
I have two questions based on this output.
1) Why without the additional wildcard i.e. *.ini
at the end does the environ.ini
file that I expect to see not show up ? I checked the name of the file there are no additional spaces or characters at the end.
2) why does these two files
etc\ENVIRON.INI_20150902_0944
etc\ENVIRON.INI_20150903_1035
show up without the added wildcard at the end i.e. without *.ini*
. I expect I would only see .ini
files only.
Also testing this on another machine
findstr /i /s /m /c:\output *.ini
etc\billdirfile.ini
etc\doc1dirfile.ini
etc\ENVIRON.INI
etc\ENVIRON.INI_20150825_1521
the findstr command finds the etc\environ.ini
file without an issue. Both machines are running server 2012 R2 and are exactly the same. Any help would be greatly appreciated.
Thanks,
Mack
Upvotes: 0
Views: 1082
Reputation: 49097
When using in a batch file just file name of a console application like findstr
without file extension and without complete path, command line processor searches first in current directory and next in all directories defined in environment variable PATH for findstr*
and checks if any found file has a file extension defined in environment variable PATHEXT.
To see the current values of PATH and PATHEXT run in a command prompt window set path
which lists all environment variables starting with path
in name.
As NTFS file system driver returns file names always in alphabetic order, a findstr.bat
is used first by command processor as found first prior to findst.exe
perhaps also existing in same directory which is often not wanted. By the way: Internal commands of cmd.exe
like echo
are used only if no executable file could be found having name echo
and a file extension listed in PATHEXT.
So it could be that just findstr
in the batch file does on one of the two computers not result in executing findstr.exe
in system32 directory of Windows, but in using a different findstr.*
found in one of the directories in PATH having a file extension listed in PATHEXT.
It is always more safe to specify in batch files console applications like findstr.exe
with full path and with file extension, i.e. use %SystemRoot%\System32\findstr.exe
instead of just findstr
.
You should check if there is a file with name findstr
with a file extension listed in PATHEXT in any directory listed in PATH. The batch file CheckPath by Jason Faulkner could be useful to find out if there is findstr.bat
or findstr.com
or finstr.exe
and in which directory of PATH found first.
The answer for your second question why with *.ini
also ENVIRON.INI_20150902_0944
and ENVIRON.INI_20150903_1035
are processed by findstr is:
The short names of the files are ENVIRON~3.INI
and ENVIRON~4.INI
.
(The numbers are most likely different on your computer.)
The kernel function used by findstr and dir for searching for files with a given pattern takes also the short file names into account and not only the long file names. Run dir /S /X *.ini
and you see all files found with *.ini
because of a match on long or short file name.
I have no idea why environ.ini
is not listed on first output. Perhaps you can find out the reason by looking on short names of all *.ini
in directory etc
.
Upvotes: 1