Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest way to delete a tree of directories in batch file

I need to write a batch file that received a directory that contains a huge number of empty sub-directories and deletes them all.

What's the fastest way of doing this? (by fast I mean not like what Windows Explorer does when you try to delete such a directory...)

Clarification:

I'm not trying to delete only empty directories. It just so happens that this dir I'm trying to delete is mostly empty sub-dirs.

like image 595
Assaf Lavie Avatar asked May 25 '09 05:05

Assaf Lavie


People also ask

How do I delete a directory tree?

To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.

What is the fastest way to delete big folders?

Right-click the Shell (folder) key, select New, and click on Key. Name the key Quick Delete and press Enter.

Is rmdir faster?

del /f/s/q foldername is good too, but it leaves behind the directory structure. This is nearly three times faster than a single rmdir, based on time tests with a Windows XP encrypted disk, deleting ~30GB/1,000,000 files/15,000 folders: rmdir takes ~2.5 hours, del+rmdir takes ~53 minutes.


1 Answers

rd yourdirname /s/q

Will do the job regardless of whether they are empty or not.

like image 192
kenj0418 Avatar answered Oct 09 '22 02:10

kenj0418