Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Count Files across multiple directories
Name: artod4789 Date: May 19, 2009 at 12:38:37 Pacific OS: Windows Subcategory: Batch
Comment:
I'm trying to come up with a bat file to count the amount of files of a certain name and output it to a certain file. I can do that through:
dir /a /s d:\dir\ex20090518.log | find "" /c /v >count.txt
However, I want to do this through multiple directories at once. So basically, I want this:
dir /a /s d:\dir\*\*\*\ex20090518.log | find "" /c /v >count.txt
Name: ghostdog Date: May 19, 2009 at 17:50:17 Pacific
Reply:
/s option of dir enables you to recurse directories already...
0
Response Number 2
Name: artod4789 Date: May 20, 2009 at 06:44:36 Pacific
Reply:
Then I don't get why it is not working. I know those files exist in those locations. So any thoughts why it doesn't work? I'm getting a "The filename, directory name, or volumen label syntax is incorrect" error. Not sure how that could be when I know the file with that name exists, the directory structure is there and the volume label is fine.
Any other thoughts?
0
Response Number 3
Name: artod4789 Date: May 20, 2009 at 06:53:32 Pacific
Reply:
I've gone back and done a static test where I filled in the *'s with actual directory names and it works fine. But the moment I put in an asterisk, it fails.
0
Response Number 4
Name: klint Date: May 20, 2009 at 09:20:14 Pacific
Reply:
Don't use an asterisk, just name the top-level directory where you want it to start searching downwards.
0
Response Number 5
Name: artod4789 Date: May 20, 2009 at 09:56:33 Pacific
Reply:
So then how would that work? Like this?
dir /a /s d:\dir\ | find "" /c /v >count.txt
And how would I specify a particular file name? Basically I would be looking for fileA.log and not fileB.log or any others.
Thanks for all of the help!
0
Response Number 6
Name: artod4789 Date: May 20, 2009 at 10:01:18 Pacific
Reply:
Well, I found it!!!
dir /a /s d:\dir |find "fileA.log" /c > count.txt
Works perfectly!!! Thank you all so much for your help!!!!!
Summary: I need to count the number of files in a directory. I used the following DOS Prompts-- Go to respective folder-- Set Count=0 ....... Dir * If not ErrorLevel 1 Set /A Count=%Count%+1 ....... Echo %Coun...
Summary: Hi, i am making a batch file and in that one task i need to follow that is to count file in a single folder and count files in 5 different folders. i have found out the command which gives me a count ...
Summary: Hello all, I've been trying to get a batch file that will go to a specified directory count the number of files (any file and a files with a specific extension, we're searching multiple dir's) and...