Do you want to find and delete all unwanted zero sized/empty files, recursively from all subfolders? This post explains how to accomplish that with a one line CMD command.
Find empty files
forfiles /S /M * /C "cmd /c if @fsize EQU 0 echo @path"
- If you just want to print the file name and do not need the full path, you can use @file in the place of @path.
- You can restrict the files selection to a certain type. If we need to do only for log files, you can use *.log with /M option. Example below.
forfiles /S /M *.log /C "cmd /c if @fsize EQU 0 echo @path"
How to delete empty files
The below command would delete all zero sized files, recursively in all subfolders, provided the user has permissions to do so.
forfiles /S /M * /C "cmd /c if @fsize EQU 0 del @path"
Be sure to to dry run the command and check the list of the files the command would delete. Use ‘echo’ in place of ‘del’ in the command, as shown in the previous case above.
To delete all zero size log files from all the subfolders, run the below command.
forfiles /S /M *.log /C "cmd /c if @fsize EQU 0 del @path"
We can even search for files with size less than certain value. For example, to find all files with less than 1KB size, the command would be
forfiles /S /M * /C "cmd /c if @fsize LSS 1024 echo @path"
You might also want to read