Deleting files older than 6 hours

Home Forums Scripting General Scripting Deleting files older than 6 hours

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    krokkie
    Member
    #156160

    I would like to write a script that can be set up as a Scheduled Task to delete files older than 7 hours from a few folders
    The folders are:
    D:SDMAPPDomInfoPlans
    D:SDMAPPDomInfoHourly Metars
    D:SDMAPPDomInfoHourly Tafs
    D:SDMAPPIntlInfoPlans
    D:SDMAPPIntlInfoHourly Metars
    D:SDMAPPIntlInfoHourly Tafs
    D:SDMAPPIntlInfoNotam Briefs
    D:SDMAPPIntlInfoWx Briefs

    I would also like to log how many files are deleted from each folder.

    I found this vbscript through Google, and am not sure if this is the best way of doing it, and how do I change the script to do what I need:

    strFolder = “C:Folder”
    Set objShell = CreateObject(“Shell.Application”)
    Set objFolder = objShell.Namespace(strFolder)
    Set objFSO = CreateObject(“Scripting.FileSystemObject”)

    For Each strFileName in objFolder.Items
    If len(objFSO.GetExtensionName(strFileName)) > 0 Then
    Set objFile = objFSO.GetFile(strFolder & strFileName.Name)
    If DateDiff(“N”,objFile.DateLastModified,Now()) > 360 Then
    objFSO.DeleteFile(strFolder & strFileName.Name),True
    End If
    End If
    Next

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.