Delete Files Older 1 Week Date Modified

Discussion in 'Windows Server' started by Joe K., Jun 12, 2006.

  1. Joe K.

    Joe K. Guest

    I would like help to create a script that can be used in the Schedule Tasks
    that will delete files older than one week ago. This script will be executed

    I would like to delete files older than one week ago from the following

    Please help me complete this task.
    Joe K., Jun 12, 2006
    1. Advertisements

  2. Joe K.

    jasonboche Guest

    I think you would have much better luck posting this question in a scripting
    newsgroup. I'm not (yet) knowledgeable enough with scripting to provide a
    good script for you to do this.

    jasonboche, Jun 12, 2006
    1. Advertisements

  3. Here ya go.
    Save the contents between "--- script ---" and "--- end of script ---" to a
    ..vbs file (cleanup.vbs or something like that). Schedule that with a user
    that has the correct permissions to delete files from the share.
    --- script ----
    Option Explicit

    Const FOLDER_NAME = "\\CAL\f$\"
    Const AGE_IN_DAYS = 7

    Dim objFSO, objFolder, objFileCollection, objFile
    Dim strFileDate

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder(FOLDER_NAME)
    Set objFileCollection = objFolder.Files

    For Each objFile In objFileCollection
    strFileDate = FormatDateTime(objFile.DateLastModified, 2)
    If DateDiff("d", strFileDate, Date) > AGE_IN_DAYS Then
    objFSO.DeleteFile objFile.Path
    End If
    --- end of script ---
    Erik Nettekoven [MCSE], Jun 13, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.