Solved

Script to delete files older than 15 min.

Posted on 2011-03-09
4
682 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using VBS. How can i pull out the list of Memory (Private Working Set)? 3 71
VBA Vbscript  Issue 9 42
xcopy using a text file to a folder 13 79
Upgrade dos 4.00.1111 11 67
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…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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