Link to home
Start Free TrialLog in
Avatar of charlespliler
charlesplilerFlag for United States of America

asked on

Script to delete files older than 15 min.

I have another script question. I have a script to delete files on individual Servers that runs after a copy process. Currently it deletes files that are older than 6 or so hours old. Because the copy process runs every 6 hours I am getting duplicate files. I need the script to delete files more than 15 minutes old.
Here is the current script.

Dim fso, f, f1, fc, result
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFolder("d:\gcti\logs\ksc_sip_agent_1\archive")
   Set fc = f.Files
   For Each f1 in fc
     result = CSng(Now) - CSng(f1.DateLastModified)
     If result > .25 Then
        f1.Delete
     End If
   Next
   Set fso = Nothing
   Set f = Nothing
   Set fc = Nothing
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

If you want to keep the rest as is then the ".25"  is 1/4 of a day so if you change it to:

result = CSng(Now) - CSng(f1.DateLastModified) * 60*24
     If result > 15 Then
        f1.Delete
     End If

that will make it in minutes rather than days

Steve
ASKER CERTIFIED SOLUTION
Avatar of prashanthd
prashanthd
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok, glad i bothered.

Steve