224

I want to delete a folder that contains thousands of files and folders. If I use Windows Explorer to delete the folder it can take 10-15 minutes (not always, but often). Is there a faster way in Windows to delete folders?

Other details:

  • I don't care about the recycle bin.
  • It's an NTFS drive.
apxcode
  • 7,696
  • 7
  • 30
  • 41
BrezzaP
  • 2,463
  • 3
  • 15
  • 10
  • 1
    Also asked here at Super User: http://superuser.com/questions/19762/mass-deleting-files-in-windows/289399#289399 – Hugo Jun 01 '11 at 21:51
  • 1
    Maybe rm -rf in cygwin is faster, and maybe a linux live cd rm -rf is faster still. – barlop Jan 14 '13 at 06:22
  • using cygwin ls DIRECTORY > list_files and do a iteration over the list_files and use rm -rf ( dealing with a 1TB large file pool and works well ) – gnuyoga Oct 12 '13 at 09:02
  • Guys, i'm not sure if this is the same experience everyone else has... but if I delete a big folder and then cancel it while it's deleting the folder is gone and the recycle bin is empty. Not sure why this works, but it does for me. – ladieu Feb 19 '14 at 18:08

6 Answers6

1099

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 at Super User.

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.

Technet documentation for del command can be found here. Additional info on the parameters used above:

  • /f - Force (i.e. delete files even if they're read only)
  • /s - Recursive / Include Subfolders (this definition from SS64, as technet simply states "specified files", which isn't helpful).
  • /q - Quiet (i.e. do not prompt user for confirmation)

Documentation for rmdir here. Parameters are:

  • /s - Recursive (i.e. same as del's /s parameter)
  • /q - Quiet (i.e. same as del's /q parameter)
Hugo
  • 27,885
  • 8
  • 82
  • 98
  • @Hugo a question: In the above timed tests, for either or both methods, did you count the files immediately before you ran the method? I'm asking because the folder contents might already be in the OS file cache. Thanks! – William C Apr 10 '12 at 15:20
  • @WilliamC: I don't remember exactly, but for the repeated deletes with the same contents I will have counted immediately before only one delete, and won't have repeated it for the other deletes (as I already know the numbers). – Hugo Apr 10 '12 at 17:20
  • 2
    I tried this today (admittedly on a smaller dataset) and got the opposite result: using just rmdir was 30% faster (3:17) than using del and then rmdir (2:15). – Harry Johnston Apr 26 '12 at 19:21
  • @HarryJohnston: Interesting. I had a huge number of files and folders, perhaps it depends on these factors. (PS did you accidentally switch your numbers?) – Hugo Apr 27 '12 at 08:44
  • @Hugo: yes, I did - doh! del/rmdir 3m15s, rd 2m15s. You say you may have scanned the directory tree (to count the files) in some cases ahead of your original tests; in some work I've been doing recently I found that scanning ahead of time sped up similar operations enormously, so it is possible that this significantly distorted your results. If I get a chance I'll run another test with a larger number of files. – Harry Johnston Apr 28 '12 at 02:49
  • It's also possible that the behaviour depends on the OS (I was using Windows 7) and/or disk encryption (my disk was not encrypted). – Harry Johnston Apr 28 '12 at 02:50
  • 6
    I needed to "Run As Administrator" to get this to work, depending on the drive. – Eyal Jul 06 '12 at 15:25
  • 1
    How about using Cygwin. I know it's a layer on top of Windows but can the linux world help us serving better? – sarat Aug 14 '12 at 04:43
  • Very fast, although it chokes on too long paths, but you can use total commander shift+f8 for the remaining stuff – vinczemarton Apr 04 '16 at 13:36
  • I've been using `rmdir /s/q foldername > nul` with great success. If it complains about "directory not empty" (rare), simply run the command again. – Marc.2377 Nov 12 '16 at 01:06
  • 1
    This worked great for me. It deleted about 16 GB, a couple hundred-thousand files in seconds on Windows 7. The OS was hanging on that for a while before I gave up and searched here. – Engineero Jan 11 '17 at 14:26
  • Really kool. Can I print the progress also while deleting? – AndroDev Apr 01 '17 at 10:07
  • 1
    @AndroDev No, this is meant for speed only. The progress calculations are probably part of why Windows Explorer is so slow. – Hugo Apr 02 '17 at 08:15
  • I have created a little batch tool. https://gist.github.com/Gaspadlo/4c22d07f5ee92a6bd91f379953664aa6 It contains confirmation prompt with path recap and in the end it prints out when the deletion started and when it ended. – Adam K. May 12 '17 at 12:32
  • 15
    An excellent and elegant solution, can I suggest we streamline the command by using the command shell ampersand: Run commands in succession: `del /f/s/q foldername > nul & rmdir /s/q foldername` or Run commands in succession only if the first command is successful. `del /f/s/q foldername > nul && rmdir /s/q foldername` – GBGOLC Aug 11 '17 at 13:59
  • If you are using cmd.exe, then also adjust it's priority in task manager. "Realtime" priority was MUCH faster for me than normal priority. – NicoJuicy Nov 16 '17 at 15:04
  • 3
    ps. a nice explanation & shell integration solution here: http://mattpilz.com/fastest-way-to-delete-large-folders-windows/ – JohnLBevan Dec 21 '17 at 13:42
  • 1
    I've found that pausing Windows Indexing before starting the del + rmdir operation helps further speed up the deletion task. Noticed the indexer was using up a significant portion of my disk I/O bandwidth (in task manager), most likely taking into account the the lose of files. – pacificgilly1992 Feb 22 '19 at 21:46
  • 1
    `del` is better because it allows wildcards. `rmdir` doesn't. – Denis Mar 22 '19 at 18:36
  • I was looking for the fastest way to delete corrupted node_modules. rmdir /q/s node_modules was taking a long time. But this solution worked very fine and reduced the deletion time considerably. – Chris Claude Feb 26 '22 at 12:39
  • Convenient batch version of these commands: https://gist.github.com/ciscoheat/d2e2e182122cdf3f0f179625d922c3a7 – ciscoheat May 11 '23 at 06:47
  • @pacificgilly1992 disabling windows indexing seems to have made a huuuge difference for me. I'm trying to delete over a million files, and it was doing about 1 file per second, but after I disabled indexing on search, now it's flying through them, and appears to be doing maybe up to 1000 per second. – Vincent Jul 22 '23 at 17:57
399

Using Windows Command Prompt:

rmdir /s /q folder

Using Powershell:

powershell -Command "Remove-Item -LiteralPath 'folder' -Force -Recurse"

Note that in more cases del and rmdir wil leave you with leftover files, where Powershell manages to delete the files.

Simon Streicher
  • 2,638
  • 1
  • 26
  • 30
Stephen Denne
  • 36,219
  • 10
  • 45
  • 60
  • 24
    btw, you can also use rd /q/s however, while this is faster than the graphical representation inside Windows Explorer, it is still going to take a *long* time - MS uses a 'Schlemeil the Painter' algorithm (joelonsoftware.com/articles/fog0000000319.html) anytime a dir or del is done – warren Oct 09 '08 at 11:36
  • 40
    rm -rf folder works wonderfully fast if you have Cygwin installed. – Sinan Ünür May 23 '09 at 14:18
  • 49
    I used to use this, but I've found a combo of del+rmdir nearly three times faster than plain rmdir. See my answer: http://stackoverflow.com/questions/186737/whats-the-fastest-way-to-delete-a-large-folder-in-windows/6208144#6208144 – Hugo Jun 01 '11 at 21:50
  • 3
    Sinan's suggestion is the fastest. Install http://www.cygwin.com/ then use rm -rfv folderName from the cygwin command prompt. – Lonnie Best Jan 08 '13 at 20:34
  • 1
    As Hugo mentioned, it has been found that del+rmdir can be faster: http://superuser.com/a/289399/155435 – mrswadge Nov 21 '13 at 10:42
  • 1
    it cna't delete files with very long filenames. – Jürgen Paul Dec 20 '13 at 05:58
  • Thanks Hugo, just found my build Drop folder which gets nuked on rebuild in about 8+ minutes, just got deleted with your command in less than 50 seconds. Which is amazing! Cant wait to update our build scripts. Cheers! – ioWint Sep 05 '15 at 21:12
  • 6
    The windows Git BASH shell rm -fr works quite fast as well. – Martin Dec 12 '16 at 11:53
  • I wouldn't call 100MB/min superfast but still it's an improvement on Windows Explorer. – Krzysztof Wołowski Sep 07 '17 at 06:30
8

use fastcopy, a free tool. it has a delete option that is a lot faster then the way windows deletes files.

Stephen Denne
  • 36,219
  • 10
  • 45
  • 60
  • 1
    I tried FastCopy. not sure if it is faster than windows, I was only getting 92 files / second deleted. Considering I gave up counting the number of files at over 250K, its going to take me for ever to use.. Oh well. Each file is only like 20 bytes. Darn PHP Session Files. – Chrispix Aug 28 '10 at 19:59
  • 3
    try the open source free tool RapidDeletePro: https://github.com/mhisoft/RapidDeletePro – Tony Nov 01 '18 at 03:17
  • 1
    I have to recommend RapidDeletePro. I work in a call center environment where all calls get recorded. This results in a few hundred thousand MP3 files every day and several terabytes a year. So, when purging files I did a comparison and RapidDeletePro was the fastest, next closest being del /f/s/q folder > nul at about 3 times slower. – Tyler W. Cox May 27 '21 at 02:18
6

use the command prompt, as suggested. I figured out why explorer is so slow a while ago, it gives you an estimate of how long it will take to delete the files/folders. To do this, it has to scan the number of items and the size. This takes ages, hence the ridiculous wait with large folders.

Also, explorer will stop if there is a particular problem with a file,

nicodemus13
  • 2,258
  • 2
  • 19
  • 31
2

and to delete a lot of folders, you could also create a batch file with the command spdenne posted.

1) make a text file that has the following contents replacing the folder names in quotes with your folder names:

rmdir /s /q "My Apps"  
rmdir /s /q "My Documents"  
rmdir /s /q "My Pictures"  
rmdir /s /q "My Work Files"

2) save the batch file with a .bat extension (for example deletefiles.bat)
3) open a command prompt (Start > Run > Cmd) and execute the batch file. you can do this like so from the command prompt (substituting X for your drive letter):

X:  
deletefiles.bat
Ajinkya
  • 22,324
  • 33
  • 110
  • 161
  • 2
    Yes, I have a similar batch file, but found a combo of del+rmdir the fastest: http://stackoverflow.com/questions/186737/whats-the-fastest-way-to-delete-a-large-folder-in-windows/6208144#6208144 – Hugo Jun 01 '11 at 21:54
-6

Try Shift + Delete. Did 24.000 files in 2 minutes for me.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
jeroen
  • 101
  • 1
  • 15
    See above- avoids the recycle bin but still way slower than command line. – andig May 12 '13 at 10:03
  • 1
    This method will delete files directly instead of moving them to the recycle bin, but the explorer will still try to count all files in order to get an estimate, which takes ages for large folders (> 100k files) – uceumern Feb 28 '17 at 08:21
  • what was the average file size ? – chupa_kabra Nov 15 '17 at 11:31
  • @your_boy_gorja the problem is not the average file size but the amount of files in a folder. When you delete by Explorer, the Explorer needs to read all the files to get the size and try do an estimate – Vinicius Monteiro Jan 04 '18 at 19:33
  • @uceumern yes this counting thing it does is ridiculous with a folder with many, many files (~40GB with 1m+ files) – Brian Leishman Apr 04 '18 at 13:44
  • Does not say much, you have to consider folder-strcuture and filesizes – Nikolai Ehrhardt Mar 21 '22 at 06:29