Solved

Script to delete files older than 15 min.

Posted on 2011-03-09
4
674 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:charlespliler
  • 3
4 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 35085236
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
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 35085247
Similar idea to my script here:

http://scripts.dragon-it.co.uk/links/batch-files-older-than

Steve
0
 
LVL 12

Accepted Solution

by:
prashanthd earned 500 total points
ID: 35085261
Please try the following

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 = DateDiff("n",f1.DateLastModified,Now)
    If result > 15 Then
        f1.Delete
    End If
Next
Set fso = Nothing
Set f = Nothing
Set fc = Nothing
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 35087248
Ok, glad i bothered.

Steve
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

777 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