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.

12 Responses to “Tips of How to Delete Folder Contents While Maintaining Folder Tree Structure in Windows XP PC”

  1. Paul M.
    August 28th, 2009 03:54
    12

    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”"

  2. nigel
    May 6th, 2009 04:17
    11

    greatest thing i have ever encountered. imagine that the internet is ACTUALLY helpful

  3. Alexander Char
    March 20th, 2009 02:31
    10

    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

  4. anonymous
    October 29th, 2008 03:23
    9

    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?” ???

  5. snpages.info
    October 23rd, 2008 10:41
    8

    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.

  6. Ty Myrick
    October 16th, 2008 04:59
    7

    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?

  7. jase07
    October 11th, 2008 00:35
    6

    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?

  8. jase07
    October 11th, 2008 00:29
    5

    this is great thanks

  9. Bob Learmonth
    October 8th, 2008 00:48
    4

    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

  10. Add “Empty Folder Contents” To Vista Right Click Context Menu To Delete Files Without Removing Folders » My Digital Life
    October 7th, 2008 18:24
    3

    [...] 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 [...]

  11. Alexandre
    October 7th, 2008 02:22
    2

    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.

  12. alias
    October 7th, 2008 00:09
    1

    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.

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to comments feature has been disabled. To receive notification of latest comments posted, subscribe to My Digital Life Comments RSS feed or register to receive new comments in daily email digest.

New Articles

Incoming Search Terms for the Article

delete files not folders - delete files but not folders - delete tree dos - xp delete files not folder - delete only folder content - cmd delete tree - delete all files not folders - removing files but not folders - dos command delete files leave folders - tree structure of folder - dos delete directory tree - how to delete contents of a folder from dos - delete folders but not files - delete foldes but not files - dosdelete files - delete files in a tree - how can i view all files in a tree without subdirectory structure? - windows delete files not folders - Delete folder but not contents in folder - delete tree - emptying goDaddy email folder - how to delete folders without deleting the main folder - command to delete file not folders - how to delte contents in multiple folders - software that deletes folders in a folder but saves file - how to delete the content of a folder - create folder after delete folder - how to delete folders but not files - remove everything in that folder without removing that folder - del files not folders - dos delete tree - Casio Rock File structure - how to delete a folder and all its content in cmd - can delete files but not folders - delete empty sub-folders in a directory tree. - how to move selected files maintain directory structure xp - tip how to move selected files maintain directory structure xp - windows delete selected files from directory tree - delete "folder content" cmd - delete file in folder tree - policy delete content folder - remove folders within folders - to delete the content from tree component - command to delete folder contents but not folder - delete folder and subfolders in cmd - dos erase folder content - godaddy.com email can't delete folder - How to delete folders within Folders - How to delete Slingbox Flash Tour folder in Start Menu - how to delete the contents in a folder -