Deleting files older than 6 hours

Home Forums Scripting General Scripting Deleting files older than 6 hours

Viewing 1 post (of 1 total)
  • Author
  • Avatar

    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:SDMAPPDomInfoHourly Metars
    D:SDMAPPDomInfoHourly Tafs
    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

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.