I have a working for loop to print all zip file's name under one working directory:
@echo off
setlocal
for %%i in (*.zip) do (
echo %%i
)
I have another working if block to check and print out a zip file size :
echo set FileSize=%%~z1 > %temp%\GetFileSize.bat
call %temp%\GetFileSize "720P_1500K_101399042.zip"
if %FileSize% GTR 1000 (
echo %FileSize% is greater than 1000
) else (
echo %FileSize% is NOT greater than 1000
)
Now, I am trying to combine these two pieces together to have a for loop to get all zip files under the working directory and at the same time use the if block to check the file size and then print out the size. But I was told: 1000 was unexpected at this time. why?
for %%i in (*.zip) do (
echo %%i
echo set FileSize=%%~z1 > %temp%\GetFileSize.bat
call %temp%\GetFileSize "%%i"
if %FileSize% GTR 1000 (
echo %FileSize% is greater than 1000
) else (
echo %FileSize% is NOT greater than 1000
)
)
%filesize%
is not defined, so theif
syntax is invalid. You'd need delayed expansionif
to string mode (where 2 is "greater" than 1000) (Note: this happens only with a delayed !variable! - with a "normal" %variable%,if
can correct the additional space). Change to(echo set FileSize=%%~z1) > %temp%\GetFileSize.bat
to avoid that space. Welcome to batch - the world of pain and headache.echo off
and see what's exactly executed (you should see the actual filesize) btw: you didsetlocal enabledelayedexpansion
before using delayed expansion, did you?)