Windows – the best way to remove 100,000 files from a Windows Directory

windowswindows-explorer

I had a user with more that 100,000 files in a single directory. The machine locks up and become unusable for a long time whilst the Explorer fills up memory and the machine can crash. Is there a simple way of dumping the directory and contents? We tried using the command line deltree and this did not seam much better.

DaveF

Extra –

We have had this problem several times with the same user (actually client). A program creates 100s of thousands of temp files during its run. If the program works correctly it does not matter as they get removed slowing as it is finished with this. But every now and again it dies leaving the mess of files. We have tried using rmdir and del etc methods and they are faster than using explorer but we generally end up with the same problems. The partition get damaged, there is an unexplained locked file, some file has a permission problem, which stops the delete from working. Normally these problem can be fixed with a reboot but in this case as this is a critical system we can't in production time. On Unix you can just do a rm -rf etc and this is quick and there is generally no real problem with it. All the command line tools we have tried don't seam to work reliably.

BTW – the application is being changed but this will not go into production for sometime and I though this problem was probably interesting to others.

Update – because we have MKS Nutcracker on the system (without the command line utilities) we got the programmer to knock together a simple rm. This is several orders faster than del/deltree etc. I find it strange that there is no such simple app readily available as a standard windows system admin tool.

Best Answer

You could use rmdir:

rmdir /s /q FOLDERNAME

Flags: /s means delete recursively, /q is the "quiet" mode.