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.
Custom Search

New Articles

Incoming Search Terms for the Article

delete tree dos - how to delete contents of a folder using cmd - delete files not folders - delete files but not folders - delete file but not folder tree - delete folder contents - dos delete directory tree - how to delete folder - delete subfolder files and tree - directory+delete files but leave folders+xp - remove directory tree but not files - delete files from tree - DOS delete folder - delete folder - delete folders from registri - delete folder content - cmd del folder and content - delete tree in dos - delete contents of subdirectories but not directories - delete folder and subfolder in cmd command - dos delete folder contents - rm remove files but not folders - empty folder cmd - remove folder long folder - remove folder in folder - tree-like directory structure of windows XP - *>\*folder cmd - contents got deleted folder not - delete directory contents - delete comtents of directory - delete contents of directory in dos - delete contents of directory using dos - delete folder within folder - delete subfolders but not contents - how to delete the contents of a folder without changing directory in windows cmd - removing files from directories without deleting tree structure - windows cmd remove directory and all folders and subdirectories - cmd delete contents of a folder - delete contents directory windows - delete subfolders cmd - delete tree cmd - How to delete windows folder and all it's contents? - how to remove folder in folder - how to delete folder using dos - winxp delete contets of folders, but not folders - cmd delete folder and contents - cmd to delete all contents of a folder - folder containts deletion - registry delete folders and subfolder - removing content of folder -