Search code examples
windowscommand-linecommanddirectory

How to delete empty folders using windows command prompt?


I need to delete all empty folders from my application folder using windows command prompt?

How can I create a bat file like that?

Please help me.


Solution

  • for /f "usebackq" %%d in (`"dir /ad/b/s | sort /R"`) do rd "%%d"
    

    from: http://blogs.msdn.com/b/oldnewthing/archive/2008/04/17/8399914.aspx

    Of course I'd test it first without deleting before I do that command. Also, here's a modded version from the comments that includes folders with spaces:

     for /f "usebackq delims=" %%d in (`"dir /ad/b/s | sort /R"`) do rd "%%d"
    

    P.S. there are more comments in the blog post that might help you out so be sure to read those too before you try this out