How do I remove 1,000,000 directories?

1

0

Possible Duplicate:
Quickest way to delete big folders in Windows?

I found that in a directory more than 1,000,000 subdirectories has been created due to a bug.

I want to remove all these directories, let's say in the directory WebsiteCache. My first approach was to use the command line tool:

cd WebsiteCache
rmdir /Q /S .

This will remove all subdirectories except the directory WebsiteCache itself, since it is the current working directory. Deleting the commplete directoy is as slow as before.

rmdir /Q /S WebsiteCache
mkdir WebsiteCache

I noticed after two hours that the directoriws starting with A-H have been removed.

  1. Why does rmdir removes the directories in alphabetical order? It must take additional effort to do this ordered.

  2. What is the fastest way to delete such an amount of directories?

harper

Posted 2011-01-04T15:35:09.540

Reputation: 860

Question was closed 2011-01-04T18:30:33.457

3It deletes alphabetically because that is the way that the sequence of folders to be deleted is handed to it, not because it does some separate sorting. The folders have to be sorted somehow, a computer doesn't have a concept of taking "whatever it comes across", which seems to be what you are suggesting. – Matthieu Cartier – 2011-01-04T15:43:05.023

This question would be more useful for others if you rephrased it to apply to any similar situation (i.e. no WebsiteCache) -- the recommendations are likely the same. Also, your operating system might be interesting information. – Daniel Beck – 2011-01-04T15:43:51.653

1@beurolysis: The directories have NOT been created alphabetically. The order was like A B C A(1) B(1) C(1) A(2) B(2). How can a directory of one million entries be sorted at the disk? – harper – 2011-01-04T16:03:19.983

5@harper; The NTFS Master File Table stores all files in a sorted tree. It's not slower, because it allows for much faster file lookups, and it also means that any file requests will be served alphabetically. It's faster this way. – Phoshi – 2011-01-04T16:06:10.003

@Phoshi: Any idea to increase speed? – harper – 2011-01-04T16:21:20.937

One hack is to MOVE the files (should be instantaneous) and then delete them later. I have seen game (un)installers kill a 9gb folder instantly, not sure the method... – horatio – 2011-01-04T16:40:10.217

Can't you do 'rmdir /Q/S WebsiteCache' and then recreate this directory? – Wacek – 2011-01-04T16:46:03.167

3windows is not very fast at deleting large numbers of files/folders, I think that there is not really any way to quickly delete that many items. just bite the bullet and run the delete overnight – Patrick – 2011-01-04T17:15:14.533

No answers