Reputation: 341
Using the code below I am able to count the number of files in a directory and call another batch file if the number of files in the directory equals (EQU or ==) say 20 When i use LSS i run into a few problems. The results are problematic and i am getting unexpected results depending on how many files are in the directory or the value of LSS If for example i have 9 files in my directory and LSS set for say 15 the call command doesn't work. Is there a way to fix this possible number Vs string issue. I have also tried using "" around the numbers but still no luck. Any help would be appreciated
@ECHO OFF
SETLOCAL
SETLOCAL ENABLEDELAYEDEXPANSION
SET count=0
for %%o IN (C:\test1\*.*) DO (
echo %%o
SET /A count=count + 1
)
echo %count%
IF %count% LSS 20 call RunAll.bat
ENDLOCAL ENABLEDELAYEDEXPANSION
ENDLOCAL
Upvotes: 0
Views: 30
Reputation:
you setlocal enabledelayedexpansion
but you do not use its functionality. It makes more sense to wrap your if
in double quotes or square brackets.
Lastly, no need to call RunAll.bat
just can it without call.
@echo off
setlocal enabledelayedexpansion
set count=0
for %%o in (F:\CSV\*) do (
echo %%o
set /A count=count + 1
)
echo !count!
if "!count!" LSS "20" RunAll.bat
endlocal enabledelayedexpansion
Upvotes: 0