DIR wildcard weirdness
Posted: 30 Jul 2014 12:36
I have 1,011 batch files sitting in a folder.
I have exactly 7 of these batch files that end in 1.bat (clientname1.bat) etc...
Yet look what happens when you try to do a wildcard to find all the files that end in 1.bat
For the sake of brevity I am piping it to show you the count of all the files it finds. Trust me when I say it does list all 996 outputs when I don't pipe it to find.
And just for the sake of argument lets try the FOR command. It does the same thing.
Lets see what it does with Zero at the end of the file name. I know I have exactly two batch files that end in 0.bat
Why does that work?
Lets look at 2.bat. I know I only have 4 batch files that end in 2.bat
Again, doesn't make any sense.
Weird thing is if I just put a few files in a test folder everything works out just fine.
Just so everyone doesn't think I am crazy, here is a redacted screenshot of those 7 files. I use a 3rd party file manager that allows you to put in file masks.
I have exactly 7 of these batch files that end in 1.bat (clientname1.bat) etc...
Yet look what happens when you try to do a wildcard to find all the files that end in 1.bat
For the sake of brevity I am piping it to show you the count of all the files it finds. Trust me when I say it does list all 996 outputs when I don't pipe it to find.
Code: Select all
C:\Celeris>dir *1.bat /b |find /v /c ""
996
And just for the sake of argument lets try the FOR command. It does the same thing.
Code: Select all
C:\Celeris>@for %G in (*1.bat) do @set /a count+=1
C:\Celeris>echo %count%
996
Lets see what it does with Zero at the end of the file name. I know I have exactly two batch files that end in 0.bat
Code: Select all
C:\Celeris>dir *0.bat /b |find /v /c ""
2
C:\Celeris>@for %G in (*0.bat) do @set /a count+=1
C:\Celeris>set count
count=2
Why does that work?
Lets look at 2.bat. I know I only have 4 batch files that end in 2.bat
Code: Select all
C:\Celeris>dir *2.bat /b |find /v /c ""
16
Again, doesn't make any sense.
Weird thing is if I just put a few files in a test folder everything works out just fine.
Just so everyone doesn't think I am crazy, here is a redacted screenshot of those 7 files. I use a 3rd party file manager that allows you to put in file masks.