Batch process to delete folers and bypass recycle bin on WinNT

Posted on 2005-04-23
Last Modified: 2008-01-09
I have a batch file to delete folders on a WindowsNT Server shown at the end of this question.  My problem is that the folders I'm deleting are 26GB. Is there any way to bypass the recycle bin while deleting?  

Here's the function I'm using right now:
Private Function fDeleteFolders(BackupPath,TSO)
    Dim FSO
    Dim Folders
    Dim Folder
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set Folders = FSO.GetFolder(BackupPath)
      For Each Folder In Folders.subFolders
         If DateDiff("d", Folder.DateCreated, Date) < 10 Then
              TSO.Write "Deleted: " & Folder.Name & vbCrLf
              Folder.Delete True
              fDeleteFolders = "true"
        End If
     Set Folder = Nothing
     Set Folders = Nothing
  End Function

Thanks, TT
Question by:TommyTupa
    LVL 2

    Expert Comment

    Why don't you use a simple CMD file with the delete command, so in that way you don't put the files in recicle bin.
    LVL 13

    Author Comment

    I need to delete folders older than x number of days.  Didn't think this can be done with CMD.
    LVL 15

    Expert Comment

    LVL 1

    Expert Comment

    Instead of rewriting your already fine batch file change the way your recycle bin works. Use gpedit.msc go to User Configuration, Administrative Template, Windows Explorer, open Maximum Allowed Recycle Bin Size. Enable the policy and input a number between 0 and 100% to represent the amount of disk your recycle bin is allowed to take up, all other files will be permanently deleted.

    LVL 12

    Accepted Solution

    Why not delete the recycle bin?!

    It gets places back when you reboot.

    Anyways to have the bin not deleted change the attributes :)

    attrib c:\recycler +r /s
    then run your delete program
    then change the attributes back
    attrib c:\recycler -r /s /a

    Might be c:\recycled ... not sure. Also test the /a switch.

    Just create a batchfile to first change the attribs, then run your program and then change the attribs back.
    LVL 4

    Expert Comment

    This can be done with a CMD file, but it gets a little complex in determining what the date was 90 day ago. There are also difficulties in dealing with different date and time formats that are used at the system level.
    I would recommend you find a better way of dealing with the recycle bin or use the VBS to enumerate the files that need to be deleted and then call the shell to do DEL /Q /F %path%\%filename%.
    LVL 13

    Author Comment

    I really appreciate everyone's input.  I'll do some testing later this week and follow up.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction How to create multiboot configuration with XP\Vista and Windows 7 on it? And most important question - how to do this correctly so not to have any kind of nightmares we get when system gets screwed? First of all one should realize t…
    Just about everyone has an old PC laying around.  Ask anyone in the IT industry, whether they are a professional or play in it as a hobby.  From outdated Desktops to cheap "throwaway" laptops, they are all around and not as hard to "fix up" as you m…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    732 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

    22 Experts available now in Live!

    Get 1:1 Help Now