Need a script that deletes empty folders

Do you have a script, a DOS command line or a VB script, that will cycle through a folder and delete empty sub-folders?
gtrappAsked:
Who is Participating?
 
Steve KnightConnect With a Mentor IT ConsultancyCommented:
I was going to suggest something along the lines of the batch script Amzingtech has already given you above (which works fine for me) so the only thing I would add is you could give some feedback, e.g.:

@echo off
if exist "%~1" for /f "tokens=*" %%a in ('dir "%~1" /s /b /ad ^| sort /r') do TITLE Working on "%%a" & RD "%%a" 2>NUL && echo Removing %%a

So it will hide all the "errors" about not being able to remove the non-empty dirs, will show you progress in the title bar of the cmd window, and will show which directories ARE removed using the &&echo at the end.

Steve
0
 
jramsierConnect With a Mentor Commented:
Glary Utilities will remove empty folders on your computer and it is free.  Hope that works.
0
 
AmazingTechConnect With a Mentor Commented:
RD in dos without parameters will only remove empty folders.

Take a list of directories reverse sort the list and begin removing.

Save the code as RemoveEmptyFolders.cmd

On a command line run.

RemoveEmptyFolders "C:\Windows"
if exist "%~1" for /f "tokens=*" %%a in ('dir "%~1" /s /b /ad ^| sort /r') do RD "%%a"

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.