Page 1 of 1
Counting files in folder and compare with the number.
Posted: 09 Sep 2011 18:12
by stg68
Hello,
I am trying to count files in the folder and then compare with the number. Cannot make it to work.
Your help will be appreciated:
SET TotalExpected=8
setlocal enabledelayedexpansion
SET count=dir "C:\temp" /a-d /b/s |find /v /c "::"
ECHO %count%>totalfiles.log
IF %TotalExpected% GTR %COUNT% GOTO ERROR1
Thanks!
Re: Counting files in folder and compare with the number.
Posted: 10 Sep 2011 00:13
by trebor68
Your code is wrong.
row: SET count=dir "C:\temp" /a-d /b/s |find /v /c "::"
Here the correct code:
Code: Select all
SET TotalExpected=8
setlocal enabledelayedexpansion
for /f %%a in ('dir "C:\temp" /a-d /b/s ^|find /v /c "::"') do set count=%%a
ECHO %count%>totalfiles.log
IF %TotalExpected% GTR %COUNT% GOTO ERROR1
Re: Counting files in folder and compare with the number.
Posted: 10 Sep 2011 00:20
by dbenham
trebor68 posted the solution seconds before I was ready to post the same solution
There are 2 additional very minor points:
1) The search for all lines not containing "::" will work, but it is easier to simply search for lines that do not contain the empty string "". (I'm not totally sure why this works, but it is a generic way of preserving all non empty lines using FIND)
2) You are enabling delayed expansion, but you are not using it. Perhaps you are using it elsewhere in your script
Dave Benham
Re: Counting files in folder and compare with the number.
Posted: 10 Sep 2011 10:55
by stg68
Thank to dbenham and trebor68!
PS I will remove enabling delayed expansion