Reputation: 397
I am attempting to learn how to create batch file, it's been a tough journey thus far. I am looking for a simple batch file script that can count files within a file path I can provide it with. So far I've only been able to research and find this one:
dir /a-d "C:\Users\Me\Desktop\testphotos" | find "*"
pause
In my "testphotos" folder, I have 4 sample photo files, but the batch script returns 0 files.
Upvotes: 0
Views: 111
Reputation: 202
an alternative of your script:
@echo off
set count=0
cd "C:\Users\Me\Desktop\testphotos"
for %%a in (*.*) do set /a "count+=1"
echo %count%
pause
to count only .png files, use:
@echo off
set count=0
cd "C:\Users\Me\Desktop\testphotos"
for %%a in (*.png) do set /a "count+=1"
echo %count%
pause
Upvotes: 1
Reputation: 79983
dir/a-d /b "C:\Users\Me\Desktop\testphotos"|find /c /v ""
You need to add the /b
otherwise dir
will generate header and footer lines.
the /c
swich to find
reports the line count that would be output (/coutputs the count instead).
/vmeans "don't match
and ""
empty lines, so the find
counts dir
lines that don't match empty lines.
Upvotes: 2