I have a directory, that contains ~ 3 million files in certain subdirectories on a Windows 2008 server. Manually deleting the files via SHIFT+DEL on the root dir takes ages. Is there any other way to do the deletion in a faster manner?
|
migrated from stackoverflow.com Aug 7 '09 at 21:37
|
I regularly need to delete lots of files and directories from a WinXP encrypted drive, typically around 22 GB of 500,000 files in 45,000 folders. Deleting with Windows Explorer is rubbish because it wastes lots of time enumerating the files. I usually move the stuff I need to delete to C:\stufftodelete and have a deletestuff.bat batch file to Here's the results of a quick time test of a small 5.85 MB sample of 960 files in 303 folders. I ran method 1 followed by method 2, then reset the test directories. Method 1 removes the files and directory structure in one pass:
Method 2 has a first pass to delete files and outputs to nul to avoid the overhead of writing to screen for every singe file. A second pass then cleans up the remaining directory structure:
Here's results of another test using 404 MB of 19,521 files in 3,243 folders:
So there's not much in it, probably too close to judge on a single test. Edit: I've retested with much more data, this is a typical case for me: 28.3 GB of 1,159,211 files in 146,918 folders:
Wow, method 2 is nearly three times faster than method 1! I'll be updating my deletestuff.bat! |
|||||||
|
|
If you have to delete large directory trees regularly, consider storing the root of that directory tree on a separate partition, then simply quick-format it whenever you need to delete everything. If you need to automate this, you can use this DOS command:
where Z: is your 'volatile' partition. Note: the partition must have no label. I blogged about this here. |
|||||||||
|
|
In command prompt (Start -> Run ->
|
|||||||||||||||
|
|
Use the rd /s command from the command prompt. |
|||||||||||
|
|
In addition to copying/moving files very fast (using its own API), TeraCopy can delete files and it's very fast too. Ever since finding out TeraCopy I don't use a computer without it installed (if I'm gonna copy/move/delete). The same installer installs x64 edition but to use it you have to manually force it. The beta which I recommend over the stable versions: http://blog.codesector.com/2010/09/22/teracopy-2-2-beta-3/ |
|||||||||||
|
|
The best practical solution is probably to move the folder out of the way somewhere (e.g. the Recycle Bin) and then start deleting it. It'll take ages, but at least it'll be out of the way. I'm pretty sure the time required to delete all those files is an inherent requirement of the task, not an inefficiency in the implementation of deletion. |
|||
|
|
|
I did a bat file that do the same.
it do the work in two step, one, it try to delete the files. And the second is to try to take ownership of the files. y should be changed according your local (stand for yes in english). If fail the task (for example if fail because permission) then you must run it again. However, the second round will not try to delete the files deleted in the first round, so it could be pretty quick. How to use it. Save as delfolder.bat in a path route (for example c:\windows), then run it as
where foldername is the name of the folder In my test, deleting 123'000 files took 3 minutes (sata 7200rpm). YAY! |
|||
|
|
|
Deleting folder is faster than deleting multiple files. So if you prefer to use mouse instead of command prompt, you can create directory, move files there and delete it (with Shift+Del as you said). |
|||||||||
|
|
Install Cygwin and use rm -r. But that's likely to be overkill. |
|||||||
|
|
Have you tried either of these two apps? Be sure to set the number of overwrites to 0 if you want fastest performance. Do this by clicking options then change the value at the bottom of the dialog. Enter the path to delete in the Source field and then click Delete. These apps do not put the files in the recycle bin. Use with care. |
||||
|
|
|
Do you have short file name generation enabled? If so, do you really need it? Removing a file is only a metadata opeartion. So if you've got twice the number of names to remove, the amount of work is significantly higher. |
|||
|
|
|
Using the code below usually works well for me.
|
||||
|
|
protected by Community♦ Feb 9 '12 at 23:19
This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.