Deleting files equal to 0 in a batch file

Below is an example of a simple for command that could be put into a batch file to delete the "pics.txt" file if it existed and was equal to 0. In this example, you would need to know the name of the file.

for /F %%A in ("pics.txt") do If %%~zA equ 0 del pics.txt

If you are looking for all files equal to 0 you would need to create a loop and a similar command for this to work is shown below.

FOR %%F IN (*.*) DO (
IF %%~zF LSS 1 DEL %%F
)

The above example will go through all files in the current directory, and if less than 1 in file size, delete the file.

Additional information

  • See the for command page for additional information about this command.