Deleting files equal to 0 in a batch file

Updated: 04/26/2017 by Computer Hope
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 can accomplish this with a loop. The following code is an example of a loop.

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