Solved

Script to delete files older than 15 min.

Posted on 2011-03-09
4
672 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

932 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now