Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting Files Older than 1 hour

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello I was wondering if anyone could help me with this, I am trying to work out a method that will delete all file in a given folder that are older that one hour. I have tried various tools etc but none seem suitable. Is there a way do do it with some script.

Many thanks in advance

Richard
 
Hi - this should do the trick server side

<%
Dim fso, fol, fil
Set fso = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

Set fol = fso.GetFolder(&quot;<Your folder path>&quot;)
For Each fil In fol.Files
If DateDiff(&quot;n&quot;, fil.DateLastModified, Now) > 60 Then fil.Delete
Next
%>

the fil object also has the DateCreated and DateLastAccessed properties which you may prefer to use.

Hope this helps
Mark
 
Will this actually run as a type of batch file on the machine, I am after a script which I can schedule to delete the files every couple of hours

Thanks in Advance

Richard
 
get rid of the <% bits as i think this i for asp pages.
save the file as a .vbs file then i suppose you could create an AT command on the machine where u want it to run FROM to start the vbs file every couple of hours
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top