≡ Menu

Find files with zero size

Do you want to find and delete all unwanted zero sized files, recursively from all subfolders? This post explains how to accomplish that with a one line CMD command.

Find files with zero size

forfiles /S /M * /C "cmd /c if @fsize EQU 0 echo @path"
  1. 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.
  2. 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 zero length files recursively

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

3 comments… add one
  • MazterGee

    Thanks for sharing this useful command line tip

  • David Bethke

    I tried the “Find files with zero size” version, and it’s finding all the Folder names, as well as any “Desktop.ini” files, which are small, but not Zero Bytes.

  • mike

    when I try to delete, it write me Acces Denied… ???

Leave a Comment