VBS to clear out UCEArchive

Posted on 2007-09-29
Last Modified: 2008-07-11
I would like a VBS that can look at a certain directory and delete files created over a week ago.

This will run once a day (as a scheduled task preferably) to look at my Exchange Server's UCEArchive folder - where suspect spam mail is stored - and delete any files in that folder which were created over a week ago. I need this grace period between mail going in there and being deleted so we can retrieve it if it was legitimate.

Thanks in advance
Question by:tigermatt
    LVL 12

    Accepted Solution


    Can you try  the below script? Please change the folder location

    Dim oFSO
    Dim oFolder
    Dim oFile
    Dim iDaysOld

    'Customize values here to fit your needs
          Set oFSO=CreateObject("Scripting.FileSystemObject")
          set oFolder=oFSO.GetFolder("C:\Scripts\logss")

    'Walk through each file in this folder collection.
    'If it is older than 7 days, then delete it.

    For each oFile in oFolder.Files
    If oFile.DateLastModified < (Date() - iDaysOld) Then                               
    oFSO.DeleteFile oFolder.Path & "\" & oFile.Name
    End If

    'Clean up
          Set oFSO = Nothing
          Set oFolder = Nothing
          Set oFileCollection = Nothing
          Set oFile = Nothing

    LVL 58

    Author Comment

    That's brilliant, thank you. (Points increased as I have another question below)

    How do I make it run as a scheduled task? Can I use the following command?
    %windir%\system32\cscript.exe "N:\My Settings\Desktop\ucearchive cleaner.vbs"

    LVL 12

    Assisted Solution

    Hi Tigermatt,

    You can select the file directly in the scheduled task and there is no command required

    Please try and let me know

    LVL 58

    Author Comment


    thanks Chandru
    LVL 12

    Expert Comment

    Glad I am of help!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
    When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    759 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

    11 Experts available now in Live!

    Get 1:1 Help Now