How to delete empty folders on a Windows machine

Delete Empty FoldersLooking for a way to clear some of your computer’s clutter? Getting rid of empty directories is a good start. I was looking for a file and realized that my machine was spending a long time searching through folders that I knew had nothing in them. A quick Google search returned a handy DOS trick to zap them all. It took me about one minute to delete just over two thousand empty folders. There’s nothing like a little command-line scripting to get something done.

There are 10 comments on this post

  1. Hi there…
    I just saw ur post, and tried out to empty my folders on my pc, I followed all the steps but didn’t work… no empty folders have been deleted, if you have a clue, could you pls help me? Thx a lot.

  2. I know this has been up here a while, but there is a simpler method than taking the generated text file and modifying it in Word or Notepad. You can do the entire process with two lines of code from the command prompt:

    dir /ad/b/s |sort /R >empty.txt
    for /f %i in (empty.txt) do rd “%i”

    The for command will parse the data in the empty.txt file and add it to the rd command. The quotes around the last %i allow this to work on names with spaces in them.

  3. The filenames are truncated unless I add “delims=”.

    for /f “delims=” %i in (empty.txt) do rd “%i”

    It still doesn’t work though:

    The filename, directory name, or volume label syntax is incorrect.
    The system cannot find the file specified.

    If I copy the generated command and execute it individually it does work. I’m confused.

  4. neal,

    Itried this. The results returned in empty.txt also include folders that are not empty. I am trying to remove empty folders. What am I missing?

    dir /ad/b/s |sort /R >empty.txt
    for /f %i in (empty.txt) do rd “%i”

  5. I am also working on deleting empty folders. I tried the mentioned commands and recieved
    “The filename, directory name, or volume label syntax is incorrect”

    any ideas?


  6. Another way is (change ‘FOLDER LOCATION’ to the location that needs cleaning):
    FOR /R “FOLDER LOCATION” %A IN (.) DO (RD /Q “%~FA”)

    Note: I have not tested this reader-submitted tip. Use at your own risk! — dvg

  7. Updated (~F not necessary):

  8. FOR /F “usebackq delims=” %i IN (`”dir /ad/b/s | sort /R”`) DO rd “%i”

  9. My computer skills are pretty stale (rancid?) and so I struggled with the above dos command line options. I did find a way to do this within Window though. (I have XP.) I utilized the basic Windows search function. I right clicked the top level folder (1) and chose “Search…”. In the Search window I searched for “*.*” in the “All or part of the file name”” field (2). In the “View” menu I chose “Choose Details…” and then selected the “TreeSize” option. I then selected that field in the results to sort by “Tree Size” (ascending). All of the empty folders were at the top with size 0.0. I selected those and deleted them. Done.

    I realize that this is manual and isn’t useful for regular scheduled cleanups. But it’s fast and accessible to unskilled computer users.

    (1) My “top level folder” contained dozens of folders with a few levels of subfolders.
    (2) Within the “More advanced options” the “Search subfolders” option was selected. Make sure the “…modified” and “…size…” options are not filtering results.

Add to the discussion:

I'll never share your email address and it won't be published.

What Is This? is the personal weblog of me, David Vincent Gagne. I've been publishing here since 1999, which makes this one of the oldest continuously-updated websites on the Internet.

A few years ago I was trying to determine what cocktails I could make with the alcohol I had at home. I searched the App Store but couldn't find an app that would let me do that, so I built one.


You can read dozens of essays and articles and find hundreds of links to other sites with stories and information about Ernest Hemingway in The Hemingway Collection.