Stiffs.com

Delete Empty Folders

Saturday April 21, 2007

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.

Stay In The Loop:

Subscribe via RSS or Email to receive notifications when new posts are published.

Or just follow me on Twitter!

{ 10 comments… read them below or add one }

1 Shark Sunday April 29, 2007 at 10:11 pm

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 Shark Monday April 30, 2007 at 12:30 am

Solved… thx

3 Neal Thursday October 16, 2008 at 6:58 am

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 Josh Tuesday November 11, 2008 at 11:44 pm

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 Anthony Thursday November 20, 2008 at 10:26 am

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 drew Friday November 21, 2008 at 9:58 am

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 Stu Tuesday December 1, 2009 at 5:15 pm

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 Stu Tuesday December 1, 2009 at 5:20 pm

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

9 John Wednesday August 25, 2010 at 5:56 pm

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

10 tommy Sunday December 19, 2010 at 11:53 am

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.

Leave a Comment

Previous post:

Next post: