Tips of How to Delete Folder Contents While Maintaining Folder Tree Structure in Windows XP PC
Have you came across a scenario whereby you want to delete all files in main and sub folders while maintaining folder tree structure? By default, Windows doesn’t provide such a feature and you need to do it in a very manual way, by going to each of the folders and highlight all the files you want to delete followed by a Delete button pressed. You need to repeat the same action by going to each of the sub folders until all files have been deleted. All these steps could be very time consuming and painful especially when the folder tree structure becomes more complicated. Now with this simple utility, you can delete all files in main and its sub folders while maintaining the folder tree structure with only few steps.

This feature can be enabled in right click folder menu by editing the registry key. Just follow instructions as mentioned below and you are done:
1) Go to Start -> Run, then type ‘regedit’ and press enter
2) Locate to HKEY_CLASSES_ROOT\Directory\shell
3) Right click on ‘shell’ folder and choose New -> Key, name the new sub key as ‘Empty Folder Contents’.
4) Right click on ‘Empty Folder Contents’ and choose New -> Key, name the sub key as ‘Command’.
5) Under the ‘Command’ sub key, double click on ‘Default’ as located at right panel. A small Edit String window will be pop up, then enter this value: cmd /c “cd /d %1 && del /s /f /q *.*”
6) Click OK button to save the setting.
Once this is done, right clicking on the folder (that you intend to delete the contents) and its sub folder contents, you will see ‘Empty Folder Contents’ has been added in the context menu. Just click on it and all the files in this folder as well as sub folders will be deleted without disturbing the original folder tree structure.
The empty folder contents trick also works in Windows Vista.
Related Articles
- Add “Empty Folder Contents” To Vista Right Click Context Menu To Delete Files Without Removing Folders
- Automatically Expand Navigation Pane Tree to Current Folder in Windows 7
- Turn Off and Disable Windows XP Built-in ZIP Support and Compressed Folders
- Password Protect Compressed (zipped) Folders and Hence Your Files and Folders
- Simple Tips on How to Setup Favorite Folder Directory in Firefox Web Browsers for Quick File Access
- How to Change Folder Thumbnail Preview Picture in Windows Vista Explorer
- Fast Empty Folder Finder to Clean Up Your Desktop System
- Reveal or Hide Windows System Files and Folders
- Auto Clean Up Your Folders Periodically Via Auto-Delete
- Restore Missing or Deleted Favorite Links Shell Folder










































August 28th, 2009 03:54
Using this post and info from http://blogs.msdn.com/oldnewthing/archive/2008/04/17/8399914.aspx
I pieced together this one line command to put in the “Empty Folder Contents” registry key. It gives a warning with pauses, which can be tweaked (I couldn’t figure out how to have it recognize a yes or no and quit in a one line command) and deletes everything in the directory, including empty directories.
Just follow this post and put the following in for the Default Command in the registry:
cmd /c “echo BE CAREFUL – X out of the window if you don’t want to delete directory contents && pause && echo LAST WARNING – all files and subdirectories will be deleted && pause && cd /d %1 && del /s /f /q *.* && for /f “usebackq delims=” %%d in (`”dir /ad/b/s | sort /R”`) do rd “%%d”"
May 6th, 2009 04:17
greatest thing i have ever encountered. imagine that the internet is ACTUALLY helpful
March 20th, 2009 02:31
hi i can see the context menu when i right click but when i click the menu it says
“This file does not have a program associated with it for performing this action.Create an association in the Folder Options control panel
October 29th, 2008 03:23
be careful cutting and pasting from the web page into regedit.
You may find that the “double-quotes” copied from the web page are not the same as the double quotes needed by the command.
It didn’t work for me until I deleted and reenterd the “double-quotes” in regedit. Now it works fine.
Its a bit dangerous tho. Is there a way of poping up a dialog box “Are you sure?” ???
October 23rd, 2008 10:41
Ty Myrick,
In other words, you want to get all of the files in a subfolder structure and put them in a single folder.
Use the first comment from alias above,
but instead of delete all the files, cut these files and then paste into a new and empty folder.
October 16th, 2008 04:59
Is there any way to do the reverse of this? Sometimes I want to delete a subfolder structure without deleting the files within it. Is there any way to delete a folder and move the files up in the hierarchy?
October 11th, 2008 00:35
hey! what if i wanted to delete all the contents in the folder by using the context menu what string should i place in the dafault key?
October 11th, 2008 00:29
this is great thanks
October 8th, 2008 00:48
What are the symbols that look like reverse Bs?
in the string. I tried copying and pasting and the symbols turned to &&. Right clicking a folder showed the string entered in the reg not empty folder contents
October 7th, 2008 18:24
[...] delete and remove the files, but not the folders that storing the files. There is a trick to add “Empty Folder Contents” contextual item into right click context menu (much like how user access the “Delete” function) in [...]
October 7th, 2008 02:22
Hi, [alias] said it all, F3 does work. I´ve tried editing the registry as told above for the tip in Windows Vista x64, the instruction appears in right click menu, but did not delete anything.
October 7th, 2008 00:09
an alternative would be to press F3, use * to search for all the files in folder. Sort by type and delete all the files and separate out all the subfolders. Would take a few seconds, would work on any computer instead of having to edit the registry.