Deleting a folder with 1 million files on Windows Server 2008

I am trying to delete a folder that has about 1 million files in it.  It is a Windows Server 2008.  It is a temporary folder containing small XML files that were I guess downloaded when a SQL Server Job was being executed that imported data from an XML Feed.

The problem is that I try deleting the files via command prompt and it just doesn't work.  I think it ends up hanging due to enumerating the files.  I am not sure how to delete all of the files without enumerating.

Any help would be appreciated!
adrian78Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott SilvaNetwork AdministratorCommented:
Have you tried (from an administrative cmd prompt);

rd "directory-path" /S /Q

Open in new window


This should kill the directory along with all subdirectories and files.
1
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
Using RMDir (As mentioned above by Scott Silva) if far and away the FASTEST possible method for deleting all of the files.

I have gone through many experiences where I need to be rid of many files and removing the entire directory is always preferable if possible.

You may still need to let it run for an hour or two depending on your disk's performance characteristics, and RD won't write a status (which is far faster than if it did)


However, I have come up with a neat little for-loop that allows me to keep a watch on the directory for number of files to get a good watch status that does not seem to affect the speed of the over-all delete.


So Open Two Administrative CMD Prompts.

In the first one, you can Run an RD (and assuming you also need to keep this directory around just chain it with an MD at the end) as so:

RD /S /Q "C:\Path\To\Files" && MD "C:\Path\To\Files"

Open in new window


Hit enter and let that run.

Move immediately to the second CMD window and enter this code to monitor the file delete's progress:

FOR /L %L IN (1,1,32000) DO @(echo.|Set /p "=%~L - "&dir "C:\Path\To\Files" | FIND /I "File(s)"&Ping -n 1 -w 1000 1.2.3.4>NUL)

Open in new window


Hit enter and let that run.

Now you'll get a nice self-updating status of the file count once per second (with a counter of the total number of seconds elapsed) without a lot of extra overhead. :)
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MaheshArchitectCommented:
one other option could be open folder within WinRAR and delete from WinRAR itself, you do need to install WinRAR trial version on server

I have used WinRAR to delete folders which contains files with more than 220 characters long
0
adrian78Author Commented:
Thanks guys!  The hosts manage to do it for me just before your solution was posted but I'll be using it for future.  Appreciate it.
1
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
Glad to Help Adrian :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.