This is a read-only archive. No new posts or registrations. Privacy Page Still need help? Ask the volunteers at Geeks to Go, free.
Software

How to delete a very large folder

19 min read

This thread's last reply is from . Advice, software, and links below may be out of date — treat specific steps and download links with caution.

Its not because the files are too big for the recycle bin.. Its because Explorer cannot efficiently handle that many files. It loads massive amounts of un-necessary data about the files into RAM before ever even touching them. When all the RAM is used up it continues to shove. Less than 2000 files is enough to eat up all 2GB of RAM on my laptop and bring the system to a halt. The only solution to get my system back is to open task manager and kill the explorer process and re-run it. Or, just wait, a really long time. I experience this problem very often when trying to manually delete temp files when a person hasn't ever cleared them out. :) You can delete the parent folder without any problems. But, if you navigate in to the folder, and select the thousands of files, and then delete those you're in for a rough ride.
Thanks for explaining Appleoddity :thumbup: Would RAM set up in dual channel mode help this, or is it lost course from the go? Because one of my machines have 4GB RAM in Dual channel. Talking theoretically here, as I have never had the need to delete so many files myself.
That was my misunderstanding about the file size, it was simply a conclusion I drew, but although I was correct about it being to big for the system to handle, I was wrong in thinking it was the bin that had a problem, when in fact it's the system itself, so Thanks for the correction. As to using the command line, I suggested using dos mode thinking it may be better because it isn't having to deal with the OS running at the same time, but it was only a thought, not actually sure if that would be true or not. As to the ram, my guess is it will help, but if the system can't handle the size the ram wont make a massive difference, mainly in the time frame it takes to tell you it can't manage it, but it wont make getting rid of the files any easier would be my guess.
If you don't like using the command line then install one of the alternative, free file managers like Ultra Explorer , EF Commander or similar. They may not have the huge resource requirements that Windows Explorer has.

See here: http://www.google.com/search?hl=en&q=f…G=Google+Search

I've not used any of them extensively, though I tried UltraExplorer and it looks and feels a lot like Windows Explorer.

Another possibility would be Explorer Plus 10 (Free Trial).
If CMD commands don't work I can make you a program to let you select the directory and then it will delete every file in it 10 at a time every 5 seconds or so to avoid crashing like Windows Explorer does.

I just wanted to take the time to thank everyone for all their suggestions.

As I stated earlier I won't have access to the computer until Monday at the earliest. I think I will probably try the command line solution first.
It seems like the quickest and easiest way to rid myself of this headache.

As soon as I get a chance to try out the suggested solutions I will be sure to post back here and give you my results.
Or worst case scenario I be back for some more suggestions.

@abydos - 4Gb of dual channel memory will just be able to be filled up twice as fast. :) 4Gb will allow you to handle more files at once. I think it might even be a memory leak in explorer. Because, even if you try to delete a large number of files and watch it in task manager, it will take up a lot of memory, and when it is finished, explorer will continue to hold on to all that memory for a few minutes before the Windows kernel cleans things up. I was thinking about it, and I'm not exactly sure why Explorer needs to do anything with these files before deleting them. If I remember right, it doesn't tell you how much time you have left, or show a progress indicator when deleting files. So, why does it have to know anything about the files before deleting them? Just delete them for crying out loud! :) Yet, everytime you try to delete a folder with a lot of files and folders it takes a long time while it does something before it prompts to confirm that you want to actually delete the files, and then finally it will start deleting them. Just poor design that should've been fixed a long time ago. @vectris - Create a program for me that I could link into a right-click context menu. When I right-click a folder, I want an option called "Delete It Fast" that will call your program and begin deleting the folder and files immediately. You should be able to use some low level Windows API calls to delete these files so you won't need to do any fancy work with grouping 10 files at a time, etc. The program needs to ignore any read errors or other failures when it tries to delete a file, which is another BIG annoyance with Explorer. There is always, inevitably, one file or two that are either in use or for some reason can't be deleted (usually a bug in explorer that can't handle the filename, like I mentioned earlier) and explorer will stop every time instead of just finishing the job at hand. If you really want to get fancy, I would also like the program to automatically change NTFS permissions so that it can access any files that are otherwise inaccessible as long as the program is run as an administrator. Overall, explorer takes incredibly too long to actually delete files seems how all it has to do is remove the entry from the file table, if you aren't "copying" the files to the recycle bin. I figure some low level API calls will do this task perfectly without any of the overhead. Can you make this program free too while you are at? :friends:
Well when deleting files in VB.Net the Kill command skips the recycle bin and just deletes the file. I need to find some APIs for getting permissions and there maybe an error surpresser parameter in the Kill command. As for actually deleting the files, the program could just delete the folder but then that would be basically the same as Windows Explorer, minus any APIs that I can get to make it slightly more advanced. Maybe just looping through the files one by one and deleting them, it wouldn't take as long as it sounds, and it should take a lot less CPU usage and RAM since it's just one file at a time. Also, if it was one file at a time I could get the size of each one and at the end tell you how much space you cleared =) Oh and as for the context menu, I'm pretty sure theres a registry key for that, you wouldn't happen to know what it is would you? I'll probably have to google for it later. EDIT: I completely forgot, I have no idea how to get the folder that was selected when the user right clicked it. Is there some kind of API that will return data like that?
I think your idea of looping through the files and deleting them one at a time is the way to do it. That's what I had in mind anyways. If the built in kill function does it efficiently, then use it. You should be able to trap any errors the kill command would generate. As far as the context menu goes, I do not know right off hand how to do it. But yes, you add it to the registry. And, when you click the "Delete It Fast" menu item, it will have the information in the registry as to what program to call, and what parameters to pass. Unfortunately, considering I might select and right-click several thousand files, I'm not exactly sure how that information is passed to your program because that would be a REALLY long command line if we were only talking about command line parameters. :) EDIT: The program will need to be able to accept a selection of folders and files. Basically, if I highlight folders and files, and right-click them, your program needs to be able to handle that. Looks like some good google searching needs to be done. If you're anything like me, this is your favorite part of the whole thing, actually googling for information on how to do things that you didn't know how to do, and then do it. :)
Well I meant that the user can select the Folder and choose delete and then my program will go through all the files in that folder. The user doesn't necessarily have to select all the folders themselves. As for receiving the data I'm still looking. I haven't yet searched receiving parameters though and if thats how the files are passed from the context menu then that may work.
Well, just keep in mind, the problem here that we are discussing is caused when thousands of files are selected and then deleted. If I just click a folder and delete that folder, even if there are thousands of files underneath it, explorer will take a while, but it will not eat up all the RAM and basically crash. However, if I navigate into a folder that has thousands of files in it, and I select all those files, and then try to delete them that way - we have a problem. :)

So, the main purpose of your program would be to resolve this problem by allowing me to select 4,000 files and then right-click -> Delete It Fast.

However, the added ability to handle files and folders would allow us to also bypass the overhead that Explorer has even when trying to delete a folder that contains a lot of files and folders.

I just researched some of this context menu stuff. Its very interesting. Obviously, there are a few different ways to do this. I didn't find anything definitive. I added a test item to my context menu. Basically, I created a command like this cmd /K "echo %1" to my right-click menu. %1 is the parameter passed to the echo command when I click this context menu item. If I right-clicked one file and selected this test command, sure enough, a command prompt window opened and I got the filename (not the path, interestingly enough) echoed to me. However, if I selected multiple files, and then tested this command, I didn't get one long list of files echoed to the command prompt. Instead, it opened a command prompt window for each file and echoed only the one file name. In other words, for every file I selected, it ran my command. This is certainly not going to work right, so there must be another way. The secret probably lies in how the "Send to" menu works. Because, in the case of send to, I can select multiple files, and it will send all these files to one location (such as a .zip file) without running the program multiple times, once for each file. There is definitely a way to do this Vectris, and it is certainly a nice challenge. I don't believe the answer will lie in the command line parameters, simply because of the fact that it would get too long very quickly and not be valid. The command line, I believe, is limited to 255 characters. Instead, I believe that explorer will create a collection of items pertaining to each file selected and then pass a pointer to the context menu program. You just have to figure out what that interface is. :)
Alright Vectris.. Here it is: http://www.codeproject.com/KB/shell/shellextguideindex.aspx

Maybe we should create a new thread in the programming section about this project?

The above link is probably going to take you way outside your comfort zone. Not only are all the examples I find written in C++, but they are also not standard executable programs. They are DLLs and COM objects that explorer actually loads into memory and keeps available for when files/folders are right-clicked.

If you need all the information you can get try this google search: http://www.google.com/search?hl=en&q=h…mp;oq=&aqi=

You're going to have way too much fun on this project.. Its not fair!

If I just click a folder and delete that folder, even if there are thousands of files underneath it, explorer will take a while, but it will not eat up all the RAM and basically crash.


Judging by the purpose of this topic I thought that even deleting a folder would cause a crash. Otherwise OCD would just right click the folder and delete it. But I thought that was were it was crashing.

Anyways I'll look into the Shell Examples and how to do them in VB.Net and see if I can find anything. I'm a good at coding in VB but I have never had much success when trying to go outside of it and incorporate other more advanced tools.


Just wanted to post an update on how my attempt to remove such a large number of files went. It went off without a hitch. :thumbup:

I went from this :pullhair: to this :woot: in a mere 20 minutes.

@appleoddity,
Your solution worked like a charm, thank you. There was another file in the folder that she wanted to keep so I kept the command line script
just as you had written it.

@ m-r-u, 8210GUY, Vectris, Ztruker, Doug, Abydos
Thanks for all your input and suggestions.

Still having this problem?

This topic is from the What the Tech archive and can't take new replies. Geeks to Go is an active, free help community run by volunteers. Post your question there and a person, not a bot, will work through it with you.

Ask on Geeks to Go →