Discussion Locked

Needed! script to delete files xDays old

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I have a program that writes temp files out to a folder but doesn't delete them. I need something that can run automaticly that will delete any file older than 3 days (because it still may use temp files up to 3 days old). I know you can use a VB Script to do this but I don't know the first thing about that so if you tell me to use that then you better give me a good example. Or is there a utillity under the windows 2000 Resoruce kit that I could use. Anything would be great. Thanks

5 replies

by frpieper

Main
Sub Main

Dim Fso
Set Fso = CreateObject("Scripting.FileSystemObject")

Dim Folder
Set Folder = Fso.GetFolder("\\server\Backup\Development")

Dim Files
Set Files = Folder.files

Dim File
Dim FileDateTime

For Each File In Files
FileDateTime = File.DateLastModified
If DateDiff("D", FileDateTime, Date) >= 3 THEN
File.Delete
End If

Next

Set Fso = Nothing

End Sub

This discussion is closed to new replies.