≡ 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 @isidr == FALSE if @fsize EQU 0 echo @path"
  1. Note that this command excludes directories
  2. 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.
  3. 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 @isidr==FALSE 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 @isidr==FALSE 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 recursively from all the subfolders, run the below command.

forfiles /S /M *.log /C "cmd /c if @isidr==FALSE 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 @isidr==FALSE if @fsize LSS 1024 echo @path"

You might also want to read

11 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… ???

    • David

      Run Command Prompt as an administrator:

      Press the windows key. This should bring up the Start Menu.

      Type “cmd” or “command prompt” (without quotes) into the search bar.

      A program named “Command Prompt” should appear. If not, you have much bigger issues to worry about than deleting size zero files.

      Right click on “Command Prompt” and select “Run as Administrator”

      Then run the command lines above as they were presented. It should work now.

  • NoahPM

    Command should be forfiles /S /M *.* /C “cmd /c if @fsize EQU 0 echo @path” to not show folders

    • Daniel

      That’ll include folders with a period and skip files without an extension. Better to just add a check for folders.

      forfiles /S /C “cmd /c if @isdir==FALSE if @fsize EQU 0 echo @path”

  • Akhil

    It appears it is listing down all the folder names also, making it verbose unnecessary.

  • Rahul

    How can we count the empty files I mean which are Zero instead of deleting them.

  • Richard Walter

    Also you have a typo in all the examples… should be “@isdir” not “@isidr”

  • Cinezi

    Below @isidr is wrong:
    forfiles /S /M * /C “cmd /c if @isidr == FALSE if @fsize EQU 0 echo @path”

    Correct is: forfiles /S /M * /C “cmd /c if @isdir== FALSE if @fsize EQU 0 echo @path”
    but, I using: forfiles /S /M * /C “cmd /c if @fsize==0 echo @path”

    Regards !

  • LB

    Is it possible to just list the folders that contain zero-size files?
    Just for clarity, I don’t mean empty folders, I mean folders that have zero-size files in them.

Cancel reply

Leave a Comment