If you're looking for a batch DOS method to check if a file is empty (byte 0) you could use this cycle:
@ECHO OFF
FOR %%R in (log.txt) DO IF %%~zR EQU 0 GOTO :EOF
SCENARIO
I want to have a batch file which checks what the filesize is of a file.
If it is bigger than %somany% kbytes, it should redirect with GOTO to somewhere else.
[check for filesize]
IF %file% [filesize thing Bigger than] GOTO No
ECHO Great! Your filesize is smaller than %somany% kbytes.
pause
exit
:No
ECHO Um... You have a big filesize.
pause
exit
SOLUTION
If the file name is used as a parameter to the batch file, all you need is %~z1 (1 means first parameter)
If the file name is not a parameter, you can do something like:
@echo off
setlocal
set file="test.cmd"
set maxbytesize=1000
FOR /F "usebackq" %%A IN ('%file%') DO set size=%%~zA
IF %size% LSS %maxbytesize% ( echo.File is ^< %maxbytesize% bytes )
ELSE ( echo.File is ^>= %maxbytesize% bytes )
SOURCE | LINK | LANGUAGE | ENGLISH |