DELTREE – Windows CMD Command


Notice: A non well formed numeric value encountered in /home/future4tech/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/future4tech/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Notice: A non well formed numeric value encountered in /home/future4tech/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/future4tech/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Notice: A non well formed numeric value encountered in /home/future4tech/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/future4tech/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Notice: A non well formed numeric value encountered in /home/future4tech/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118

Notice: A non well formed numeric value encountered in /home/future4tech/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119

Very old versions of Windows (Windows 95 and earlier) had the DELTREE command to delete all sub-folders and files. Newer versions of Windows do not have this command, but we can easily write a short batch script to do the same thing.

Deleting from the command line is significantly faster than using Windows Explorer, often seconds instead of minutes, there is no running calculation of file sizes and no recycle bin. This does mean there is no possibility of an undo other than restoring a backup.

The two key commands required are DEL /s to delete all files including hidden and system files, followed by RD /s to remove the now empty folders.

When iterating through thousands of files, supressing the output of DEL *.* by redirecting it to NUL, will make the process run a little faster.

Delete only Empty folders

Delete all folders and subfolders below the current folder.
Copy the script below to a folder and simply double click it.

Delete the Current Folder & subfolders

This script deletes all contents of the current folder. Copy the script to a folder and simply double click it.
This version also does not delete the root folder itself. The script sets the read-only Attribute on itself.

If you use this on a UNC path like \\Server64\share1\somefolder the CMD shell will not be able to set a current directory. To avoid an automatic fallback to C:\Windows\ the script uses %~dp0 to grab the location and then pushed will, if needed, map a temporary drive.

You may also like...

2 Responses

  1. auto approve lists says:

    This web site truly has all of the information and facts I wanted concerning this subject and didn’t
    know who to ask.

  2. zortilo nrel says:

    I have read several excellent stuff here. Definitely price bookmarking for revisiting. I wonder how a lot effort you set to create such a great informative web site.

Leave a Reply

Your email address will not be published. Required fields are marked *