Reputation: 21
I want to check file size in a Windows batch script. It seems like my script is exiting instead of moving on to the next step in the script. The file condition should not generate an error and should move on to the next step. But I must be missing something or have something incorrect in the following:
:: Check size of input files
call "%DIR_BAT%\CreateLAFMessage.bat" "%~n0.bat-> %STEP_NBR% - check for size of LOM_AA_2.dat and LOM_AI.dat" %_LAF_MSG_DETAILS%
set ERROR_MSG="%DIR_IP_INTERFACES%\LOM_AA_2.dat" ZERO Byte File
set file="%DIR_IP_INTERFACES%\LOM_AA_2.dat"
set maxbytesize=0
FOR /F "usebackq" %%A IN (%file%) DO set size=%%~zA
if %size% NEQ %maxbytesize% (
echo.File is ^<> %maxbytesize% bytes
) ELSE (
goto ON_ERROR
)
set ERROR_MSG="%DIR_IP_INTERFACES%\LOM_AI.dat" ZERO Byte File
set file="%DIR_IP_INTERFACES%\LOM_AI.dat"
FOR /F "usebackq" %%A IN (%file%) DO set size=%%~zA
if %size% NEQ %maxbytesize% (
echo.File is ^<> %maxbytesize% bytes
) ELSE (
goto ON_ERROR
)
Upvotes: 2
Views: 8218
Reputation:
You have enabled the Usebackq
option in the for loop. This option uses a different style of quoting:
Therefore, adding the double quotes tells the for loop to process the file.
@echo off
set "file=%DIR_IP_INTERFACES%\LOM_AA_2.dat"
set MAXBYTESIZE=0
for /f "usebackq" %%A in ("%file%") do set /a size=%%~zA
if %size% GTR %MAXBYTESIZE% (
echo(%file% is too large
) else (
echo(%file% is ^<^> %size% bytes long
)
pause
Upvotes: 2