davidgagne.net

  • About
  • Archives
  • Twitter
  • Facebook
  • bartender.live
  • GitHub
  • LinkedIn

Delete Empty Folders

April 21st, 2007 @ 12:40 pm PDT

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.

More posts tagged:
DOS / folders / hacks / Windows

More posts categorized:
Programming Software

More posts from:
April 2007 / 2007

Post navigation

Previous Post
Previous Post Boost Your Belkin Wireless Router
Next Post
Next Post West Restaurant, Los Angeles

Responses to “Delete Empty Folders”

  1. April 29th, 2007 @ 10:11 pm
    Shark

    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. April 30th, 2007 @ 12:30 am
    Shark

    Solved… thx

  3. October 16th, 2008 @ 6:58 am
    Neal

    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.

  4. November 11th, 2008 @ 11:44 pm
    Josh

    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.

  5. November 20th, 2008 @ 10:26 am
    Anthony

    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?
    Thanks

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

  6. November 21st, 2008 @ 9:58 am
    drew

    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?

    Thanks

  7. December 1st, 2009 @ 5:15 pm
    Stu

    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

  8. December 1st, 2009 @ 5:20 pm
    Stu

    Updated (~F not necessary):
    FOR /R “FOLDER LOCATION” %A IN (.) DO RD /Q “%A”

  9. August 25th, 2010 @ 5:56 pm
    John

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

  10. December 19th, 2010 @ 11:53 am
    tommy

    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.

Comments Closed

New comments are disabled on this post.

Search


Give Easily

Give Easily

Did you know that Amazon will donate to the charity of your choice when you use smile.amazon.com to do your online shopping? It doesn't cost you anything extra, and you can make a big difference just by using this link.

  • Support A Charity

© David Vincent Gagne. All rights reserved. Custom WordPress Theme by Jacket Industries.