Solved

Script to delete files older than 15 min.

Posted on 2011-03-09
4
671 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Ok, glad i bothered.

Steve
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
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…

763 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

12 Experts available now in Live!

Get 1:1 Help Now