How to Search for and Delete Empty Folders

By Maya Austen

There are a number of software applications which can locate and delete the empty folders stored on your computer. However, you may not what to install another application onto your system--especially one that you likely won’t use very much. It involves a little more work, but you can search for and delete the empty folders on your computer by using a simple code to create a BAT file that lists all of the folders on your computer. A few edits to this file will make it execute a command that will delete any empty folders.

Step 1

Open the DOS Command Prompt by clicking “Start,” pointing to “All Programs” (or “Programs\"), pointing to “Accessories” and clicking “Command Prompt.”

Step 2

Type the following command line at the C prompt: DIR /AD/B/S | SORT /R > EMPTIES.BAT. (to type the | vertical line symbol, press “Shift” plus “\\”). Be sure to type the command as is, including the spaces. This command will create a BAT file that lists, in reverse order, all of the folders on your computer’s hard drive.

Step 3

Conduct a search for the “empties.bat” file you just created. The file is likely saved in the “C:\\Documents and Settings\\CurrentUserName” folder (in Windows XP), or “C:\\User\\CurrentUserName” folder (in Vista and Windows 7). Run the search to be sure, then make a note of the file location.

Step 4

Open Microsoft Word, then open your empties.bat file within Word.

Step 5

Go to the “Edit” menu and select “Replace” to open the Find and Replace dialog box. In the “Find what” field type: ^p (Shift+6, p). In the “Replace with” field type: “^prd ”(open quotation mark, shift+6, prd SPACE end quotation mark). Click “Replace All.”

Step 6

Edit the file. Each file name should now be encased in quotation marks, and preceded by the command rd (which stands for remove directory). For example:…rd “C:\\Documents and Settings\\ UserName\\Local Settings\\Temporary Internet Files\\Content.Word”rd “C:\\Documents and Settings\\UserName\\Local Settings\\Temporary Internet Files\\Content.MSO” …Look over the document to ensure that this pattern holds throughout. Edit where needed.

Step 7

Save the changes to the file. Go to the “File” menu and select “Save. You may receive a prompt which states that the file, “…may contain features that are not compatible with Plain Text format. Do you want to save the document in this format?” Click “Yes.”

Step 8

Launch the empties.bat file. Open the folder that contains your empties.bat file. Right-click on the file and select “Open” from the shortcut menu. This BAT file will now try to perform the remove directory (rd) command on each folder. The rd command will fail for any folder that contains a file(s).

References & Resources