Reference number: CH000754
Deleting files equal to 0 in a batch file.
Question:
Deleting files equal to 0 in a batch file.
Additional information:
Users who wish to keep their system clean from any files that have
no data within them or delete files once data has been removed
may need to delete a file equal to 0 from a batch file.
Answer: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
what file you're looking for.
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.
See our for command page for
additional information about this command.
|