Click here to Skip to main content
15,892,737 members
Articles / Artificial Intelligence / Big Data
Tip/Trick

How to Delete a Large Folder in Windows

Rate me:
Please Sign up or sign in to vote.
5.00/5 (11 votes)
26 Apr 2015CPOL1 min read 21.5K   18   7
Explains the benefits of using the command line in the large folder delete case and shows an example of the syntax

Introduction

This is a really simple tip, but it is fairly useful if you overlook it.

So, our question today is: how to delete a folder containing zillions of files and sub folders?

Well, dah, I right-click on the folder in the Windows Explorer and select "Delete"? What kind of a silly question is that, even my 2 year old daughter randomly deletes folders from my computer when I am not looking.

Background

"Experts" might mumble, "egghh, use Shift-Del to permanently delete them, it's got to be faster since it bypasses the Recycle Bin". Well ... that is true but not the right answer.

The problem with using the Windows Explorer is that it checks the content of the folder before the delete action starts. It takes its time.

Solution

It turns out that using the Delete and even the Permanent Delete option is significantly slower than using the good old command line.

Another advantage is that it will not explode in your face as the Windows Explorer might when you push it too hard.

Ok, how to then?

The basic command is: rmdir, which can be used like this:

rmdir /s/q E:\StuffToDelete\HugeFolder

However, that is a significant improvement when the subfolders` structure is also large. In such a case, you can get almost three times better performance using del before the rmdir.

The del command will delete only the files and the rmdir will handle the empty folders afterwards. E.g.:

del /f/s/q E:\StuffToDelete\HugeFolder > nul
rmdir /s/q E:\StuffToDelete\HugeFolder

NOTE: Do not make performance tests in parallel, since Windows will prioritize the Windows Explorer process over the rmdir batch process and it will thus seem to be slower (in fact, it may even freeze until the shift-del process will finalize).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer
United States United States
Senior dish washing consultant for over 25 years!

Comments and Discussions

 
GeneralThoughts Pin
PIEBALDconsult27-Apr-15 7:19
mvePIEBALDconsult27-Apr-15 7:19 
GeneralRe: Thoughts Pin
Joezer BH27-Apr-15 19:53
professionalJoezer BH27-Apr-15 19:53 
QuestionI would need some proof... Pin
Alexandru Lungu27-Apr-15 5:33
professionalAlexandru Lungu27-Apr-15 5:33 
AnswerRe: I would need some proof... Pin
Joezer BH27-Apr-15 19:57
professionalJoezer BH27-Apr-15 19:57 
QuestionYou want to see what happens when you use webdav Pin
Dr Gadgit27-Apr-15 4:09
Dr Gadgit27-Apr-15 4:09 
I wrote a webdav server which is cool and simple to use because it just needed to read the file system and sends data back to the client in an XML envolope.

Works just fine with everyones else webdav clients and to delete a folder they just send one command but no, not windows file manager and it seems that microsoft has forgot what client/server means.

Instead it does a PROFIND on the folder and then tries to delete each file one at a time and then does another PROFIND to see if the file has been deleted and makes removing a big folder soooooooooo slow.

MS File manager also does a GET on random files at times and you need to hack the registry in windows to get it to download files that are bigger than a few megs using webdav.

FAT32,NTFS is not quite what it was under XP these days and i often see empty folders that cannot be deleted (Yes show hidden,system is on) if a process has just been stopped and the .exe dead and deleted and the message you get from windows when this happens still does not help you much.

I don't pretend to know everything about 7gb of windows API's but i do know that we no longer have quite such control over the file system as we once did after trying to delete hidden index.dat spyware folders which i could not do but i did learn that you can fill them up with zero's

QuestionNice Pin
phil.o27-Apr-15 1:08
professionalphil.o27-Apr-15 1:08 
AnswerRe: Nice Pin
Joezer BH27-Apr-15 2:17
professionalJoezer BH27-Apr-15 2:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.