Home » Questions » Computers [ Ask a new question ]

Deleting large amount of files in Windows is slow

Deleting large amount of files in Windows is slow

I have a Windows XP box with an NTFS disk and deleting large amounts of files is extremely slow. If I select a folder that contains a large number of files in a tree of folders and delete (using shift-del to save the recycle bin) it takes time that seems to be directly proportional to the number of files within the folder before it even pops up the confirmation box. It then takes an even longer time to delete each file in the folder.

Asked by: Guest | Views: 466
Total answers/comments: 5
Guest [Entry]

"Is there a way to delete a folder in
Windows and not having the time taken
proportional to the number of files
within it?

I don't think so, but some methods are clearly much quicker than others.

The worst way is to send to Recycle Bin: you still need to delete them. Next worst is shift+delete with Windows Explorer: it wastes loads of time checking the contents before starting deleting anything.

Next best is to use rmdir /s/q foldername from the command line. del /f/s/q foldername is good too, but it leaves behind the directory structure.

The best I've found is a two line batch file with 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:

del /f/s/q foldername > nul
rmdir /s/q foldername

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. More info here.

This is a regular task for me, so I usually move the stuff I need to delete to C:\stufftodelete and have those del+rmdir commands in a deletestuff.bat batch file. This is scheduled to run at night, but sometimes I need to run it during the day so the quicker the better."
Guest [Entry]

"Install gnutools for windows and run:

find YOURFOLDER -type d -maxdepth 3 | xargs rm -Rf"
Guest [Entry]

"Make sure you're not backing up files to the cloud and trying to delete them at the same time!

With many cloud backup solutions files will get locked while they are being backed up and then you have to wait for them to be backed up.

If you're having this issue with say a temp directory (or something that doesn't need backing up) make sure that temp directory isn't selected in your backup set."
Guest [Entry]

"I've found that folders with several layers of directories tend to really slow down Window's ability to remove them quickly. I was working on a project where it took 5 levels to get to the node_modules folder, which is always a beast to delete, even with

del /f/s/q foldername > nul
rmdir /s/q foldername

What I end up doing in this situation is navigating down to the node_modules folder or whatever directory has the deepest levels and just start selecting and deleting about a dozen or so directories at a time. If I get multiple deletes going, this forces the Recycle Bin to work in parallel processes rather than the single thread I believe it uses, dramatically speeds up the process.

Once my deepest directory is empty, I go up a few levels and do the same thing. This has cut down deletes that have taken me over an hour to just a few minutes.

Its a very manual process and could likely be scripted with some success, but its what's worked for me"
Guest [Entry]

"did you try using command prompt
rmdir /s /q foldername"