untested
You can use find
to count the number of files and just use the count directly:
for /f %%a in ('dir /b \\ITWS2162\work\SCM\RawData\SSC_Proj\*.zip ^| find /c /v ""') do (
if /i %%a EQU 20 (
rem do what you want here when it equals 20
C:\Users\RefosLeo\Desktop\Python\motherbatch.bat
)
)
This finds exactly 20 zip files. You could change EQU to GEQ if you actually want to find 20 or more .zip files.
Though you might want the inverse -- exit when less than or not equal to 20:
for /f %%a in ('dir /b \\ITWS2162\work\SCM\RawData\SSC_Proj\*.zip ^| find /c /v ""') do (
if /i %%a LSS 20 exit
)
rem continue here with the rest of your script
C:\Users\RefosLeo\Desktop\Python\motherbatch.bat
That is anything less than 20. If you want to exit when not equal (so less than or greater than 20) you would use if /i %%a NEQ 20 exit
If you want to continue with the method you started with, I think the following might be what you were going for:
setlocal enableextensions enabledelayedexpansion
set /a count = 0
for /f %%a in (\\ITWS2162\work\SCM\RawData\SSC_Proj\*.zip) do (
set /a count += 1
if /i !count! EQU 20 (
ECHO "there are 20 files Matrioska Process starts"
C:\Users\RefosLeo\Desktop\Python\motherbatch.bat
)
)
if /i %count% LSS 20 exit
You can't put the exit inside the for loop because you'll never know until the for loop is complete that you didn't reach 20 zip files.