Looking 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.
Responses to “Delete Empty Folders”
New comments are disabled on this post.
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.
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.
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.
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â€
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”
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
Updated (~F not necessary):
FOR /R â€œFOLDER LOCATIONâ€ %A IN (.) DO RD /Q â€œ%Aâ€
FOR /F “usebackq delims=” %i IN (`”dir /ad/b/s | sort /R”`) DO rd “%i”
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.