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!
Counting files in folder and compare with the number.
Moderator: DosItHelp
Re: Counting files in folder and compare with the number.
Your code is wrong.
row: SET count=dir "C:\temp" /a-d /b/s |find /v /c "::"
Here the correct code:
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.
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
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.
Thank to dbenham and trebor68!
PS I will remove enabling delayed expansion
PS I will remove enabling delayed expansion