Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Does anyone know how I can get a file size into a variable in a DOS batch file? I need to test for a 0 byte file.

This is a file found in the Library.
With a little tweaking.....
Determine if a file is a 0 byte file without deleting it.
:: is0byte.bat
@ECHO off
COPY>nul %1 nul |FIND "1 file(s) copied"
IF not errorlevel=1 ECHO %1 is not a 0 byte file
IF errorlevel=1 ECHO %1 is a 0 byte file:: is0byte2.bat
COPY %1 nul |FIND " 0 file" >nul
IF not errorlevel=1 ECHO %1 is a 0 byte file
IF errorlevel=1 ECHO %1 is not a 0 byte file
Hope this is of help.Cloud Dancer @ World Library

It may be in "The World Library", but it comes from this page:
http://bigfoot.com/~batfiles/main/batricks.htm30. Determine if a file is a 0 byte file without deleting it.
:: is0byte.bat
@ECHO off
COPY>nul %1 nul |FIND "1 file(s) copied"
IF not errorlevel=1 ECHO %1 is not a 0 byte file
IF errorlevel=1 ECHO %1 is a 0 byte file:: is0byte2.bat
COPY %1 nul |FIND " 0 file" >nul
IF not errorlevel=1 ECHO %1 is a 0 byte file
IF errorlevel=1 ECHO %1 is not a 0 byte fileIf you want to get the file size into a variable, see #62 on this page:
http://bigfoot.com/~batfiles/main/batchfaq.htm

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |