Results 1 to 6 of 6
  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    676
    Thanks
    28
    Thanked 2 Times in 2 Posts

    Removing specific empty folders

    I have a folder containing thousands of subfolders with a structure something like this.

    Folder1
    - Subfolder1
    - Subfolder2
    Folder2
    - Subfolder1
    - Subfolder2
    Folder 3
    - Subfolder1
    - Subfolder2
    etc.

    Is there an easy way to remove all folders that are named e.g., "Subfolder2" and that are empty? The OS is Windows Server 2003.
    Last edited by Murgatroyd; 2011-08-09 at 04:48.

  2. #2
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,170
    Thanks
    47
    Thanked 980 Times in 910 Posts
    RD /S removes a directory and all sub-directories, but it doesn't test for empty directories. I don't know of an easy way to do empty directories.

    cheers, Paul

  3. #3
    Super Moderator jwitalka's Avatar
    Join Date
    Dec 2009
    Location
    Minnesota
    Posts
    6,792
    Thanks
    117
    Thanked 798 Times in 719 Posts
    Assuming Subfolder 2's actual name is relatively unique, you could download Everything Search, fire it up, type Subfolder 2. If you only want to delete folders that are empty, sort the results by size by clicking on the size header at the top. Click the first empty folder, then shift click the last empty folder to highlight all he empty folders and hit delete.

    Jerry

  4. #4
    Bronze Lounger DrWho's Avatar
    Join Date
    Dec 2009
    Location
    Central Florida
    Posts
    1,501
    Thanks
    30
    Thanked 205 Times in 163 Posts
    Server is not your daddy's OS! It's more than likely that those folders are created and maybe even needed by the OS.

    Unless you absolutely know that they are not needed, then I'd not mess with them.
    Even..... why only delete Folder2 and not Folder1, if they are all empty?
    If they are really junk, then delete that whole dang bunch of them.

    I might do a full backup of your C: drive to another HD and then delete all those empty folders and see just what happens.
    You might just find that after a reboot,they are all back again.

    Good Luck,
    Experience is truly the best teacher.

    Backup! Backup! Backup! GHOST Rocks!

  5. #5
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    676
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Thanks for your replies. The folders that I needed to remove were not OS files but were for an application, and there were hundreds of them.

    - I used the command "dir /b/s [folder] > deletefolders.txt" in the root folder to create a text file containing a list of the required folders in all subfolders with their full pathnames.
    - Then I searched for "[folder]\" in the text file to find any folders that were not empty (empty ones did not have the trailing "\"). There were only a couple, and I emptied them manually after checking that their contents were not needed.
    - Then I used search and replace to insert "rmdir" before each filename in the text file.
    - Then I renamed the text file to deletefolders.bat and ran the batch file, which deleted all the folders.

  6. #6
    Plutonium Lounger Medico's Avatar
    Join Date
    Dec 2009
    Location
    USA
    Posts
    12,631
    Thanks
    161
    Thanked 936 Times in 856 Posts
    Thanks for posting your solution. It might just help the next person with a similar problem.
    BACKUP...BACKUP...BACKUP
    Have a Great Day! Ted


    Sony Vaio Laptop, 2.53 GHz Duo Core Intel CPU, 8 GB RAM, 320 GB HD
    Win 8 Pro (64 Bit), IE 10 (64 Bit)


    Complete PC Specs: By Speccy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •