Delete File by Created Date



Derek
07-10-2005, 12:22 AM
I would like to automatically delete archived files in a particular
directory by the Created Date properties. I would like to use a batch
file or something similar to run in the Scheduled Tasks. Does anyone
have an idea on how to do this?

Derek
07-10-2005, 12:22 AM
"Derek" <anyone@yahoo.com> wrote in message
news:uq3$DdlVFHA.2768@tk2msftngp13.phx.gbl...
>I would like to automatically delete archived files in a particular
>directory by the Created Date properties. I would like to use a batch
>file or something similar to run in the Scheduled Tasks. Does anyone
>have an idea on how to do this?
>
>


To add to this, I have tried the following VB Script and it doesn't seem
to work.

--------------------
Option Explicit
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
DeleteFiles fso.GetFolder("C:\Test")
Sub DeleteFiles(srcFolder)
Dim srcFile
If srcFolder.Files.Count = 0 Then
Wscript.Echo "No File to Delete"
Exit Sub
End If
For Each srcFile in srcFolder.Files
If DateDiff("d", Now, srcFile.DateCreated) < -7 Then
fso.DeleteFile srcFile, True
End If
Next
Wscript.Echo "Files Deleted successful"
End Sub
---------------------------------------

Torgeir Bakken \(MVP\)
07-10-2005, 12:23 AM
Derek wrote:

> I would like to automatically delete archived files in a particular
> directory by the Created Date properties. I would like to use a batch
> file or something similar to run in the Scheduled Tasks. Does anyone
> have an idea on how to do this?
Hi,

In the article below there is a WSH script (vbscript) by Michael Harris
that deletes files that has not been modified in x days old in a
specific folder (and optionally all subfolders).

Put the script in a file with the file extension .vbs, and
change
file.datelastmodified

to
file.datecreated

Newsgroups: microsoft.public.scripting.wsh
Date: 2002-10-07 08:12:33 PST
http://groups.google.co.uk/group/microsoft.public.scripting.wsh/msg/14df6623fc552446?dmode=source



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx


Delete File by Created Date