Delete a huge folder in Windows help

Posted on 2009-12-17
Last Modified: 2013-12-06
I created a smtp server in IIS and before I set the security on it I had some spammers trying to use it.  Now I have around 3.5 million files in 1 folder that I need to delete.  I've tried shift delete and  command prompt.  I was able to rename the folder no problem but can seem to delete the files all at once.  Any ideas how I can delete them?

I'm running Windows Server 2008.
Question by:mattkovo
    LVL 35

    Expert Comment

    by:Joseph Daly
    Have you tried running the del command from the command line?

    Author Comment

    xxdcmast.  That's the first thing I tried.  It just hangs up and doesn't do anything.
    LVL 16

    Expert Comment


    Unlocker might be helpful in this situation.

    After installing it, right click on folder and select 'Unlocker'.

    Try it.
    LVL 3

    Expert Comment

    The files should incremental names right?  Log1234567890.log

    have you tried to do a

    "Del c:\logfolder\Log123456*.log"

    Then do a

    Del c:\logfolder\Log1234*.log
    LVL 15

    Expert Comment

    You can give Mass Directory Eraser a try to see if it can do the job quickly.

    Author Comment

    I'll try they greyknight17.  Non of the other solutions are working yet.

    Author Comment

    Still not working.
    LVL 1

    Accepted Solution

    3.5M entries in your directory will take a LONG time irrespective of your method to delete them, save reformatting your hard drive, and it will appear to hang whatever session you attempt to use to delete the records.  The trick is to ensure that you load the delete command into a session that doesn't blow up your CPU or windows threads.  I literally would expect that to take hours, if not a day or three.

    If you can afford the downtime, run a comprehensive defragment on your server firtst - that many directory entries will have scattered the directory listing.  I would expect this to dramatically affect the performance of a delete command here.

    1. open up the command line, go to the directory above the log directory and at the command line type "rmdir logs /s" and go on holiday.  At least this shouldn't interrupt the rest of your server processes.

    The only issue here will be if any of the files are currently open, this command won't complete.  If you need this directory to be live while you operate the server, then temporarily take the server process that's locking the directory offline, rename the directory, re-create it empty, and re-enable the server process, then delete the renamed directory as per above.  I've never renamed a directory with that many files in it, but I do think it'll be instant - or at most take a few minutes.

    If no files are open and the command does return, you should recreate the logs directory.

    2. Create a script file that manually deletes each file, kick that off and go home for a few days.....  it'll take a long time to finish executing, however it'll delete each unlocked file and shouldn't hang your server.  You'll need to download a fancy text editor to do this, and I'd recommend gvim (    

    steps to do this:  (You'll need plenty of spare RAM and some patience)
      1. at the command line change into the directory that has the log files
      2. assuming you have a c:\temp directory (if not, create one) type at the command line:
            DIR /b > C:\temp\delbatch.bat
      3. Open up the file in GVIM.  Gvim is keystroke sensitive, so if you aren't familiar with it, follow the keystrokes exactly.
      4. Using gvim hit the following keystrokes (without the quotes)
              ":1,$s/^/del "
          *note: ensure there is a space after the "del"
          This will create a batch file that deletes each file individually, and won't crash if one file is locked for any reason.
           To save a file, just hit ZZ  (capital letters)
       5.  from the command line in the log directory, run the batch file:
       6. Go watch the Lord of the Rings trilogy - directors cut.

    Author Comment

    hahaa.  Thanks for the help.  I will give it a shot!

    Featured Post

    Too many email signature updates to deal with?

    Are you constantly visiting users’ desks making changes to email signatures? Feel like it’s taking up all of your time? Wish you could manage all signatures from one central location, easily design them and deploy them quickly to users? Well, there is an easy way!

    Join & Write a Comment

    Redirected folders in a windows domain can be quite useful for a number of reasons, one of them being that with redirected application data, you can give users more seamless experience when logging into different workstations.  For example, if a use…
    The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
    This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
    This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now