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.
4
  • 1
    Also asked here at Super User: superuser.com/questions/19762/mass-deleting-files-in-windows/…
    – Hugo
    Jun 1, 2011 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, 2013 at 6: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, 2013 at 9: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, 2014 at 18:08

6 Answers 6

1101

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)
22
  • 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). Apr 26, 2012 at 19:21
  • 6
    I needed to "Run As Administrator" to get this to work, depending on the drive.
    – Eyal
    Jul 6, 2012 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, 2012 at 4:43
  • 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, 2017 at 13:59
  • 3
    ps. a nice explanation & shell integration solution here: mattpilz.com/fastest-way-to-delete-large-folders-windows
    – JohnLBevan
    Dec 21, 2017 at 13:42
400

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.

9
  • 24
    btw, you can also use rd /q/s <foldername> 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 9, 2008 at 11:36
  • 40
    rm -rf folder works wonderfully fast if you have Cygwin installed. May 23, 2009 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: stackoverflow.com/questions/186737/…
    – Hugo
    Jun 1, 2011 at 21:50
  • 3
    Sinan's suggestion is the fastest. Install cygwin.com then use rm -rfv folderName from the cygwin command prompt. Jan 8, 2013 at 20:34
  • 6
    The windows Git BASH shell rm -fr <folder> works quite fast as well.
    – Martin
    Dec 12, 2016 at 11:53
8

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

3
  • 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, 2010 at 19:59
  • 3
    try the open source free tool RapidDeletePro: github.com/mhisoft/RapidDeletePro
    – Tony
    Nov 1, 2018 at 3: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. May 27, 2021 at 2: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,

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
1
-7

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

6
  • 15
    See above- avoids the recycle bin but still way slower than command line.
    – andig
    May 12, 2013 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, 2017 at 8:21
  • what was the average file size ? Nov 15, 2017 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 Jan 4, 2018 at 19:33
  • @uceumern yes this counting thing it does is ridiculous with a folder with many, many files (~40GB with 1m+ files) Apr 4, 2018 at 13:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.