How to delete files equal to 0 in a batch file

Updated: 04/26/2017 by Computer Hope
Batch file

Placing the following for command into a batch file deletes 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're 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 example above goes through all files in the current directory, and if less than 1 in file size, delete the file.