Hello,

I need to delete files in a certain folder by current date minus 2.

I do not know how to do this - I've searched the archive and the web....

All suggestions will be greatly appreciated.

Thanks in advance,
Bill Burke

Delete Files by date by Doug

Doug
Tue May 25 15:34:47 CDT 2004

Try this -

dtCheck = Dateadd("d",-2,date)

set objFileSys = createobject
("scripting.filesystemobject")
set objFolder = objfilesys.GetFolder
("c:\SomeFolder\OtherFolder\")

doFolder objFolder

sub doFolder(myFolder)
set objFiles = myFolder.files
for each objfile in objFiles
if objfile.datelastmodified < dtcheck then
objfile.delete
end if
next
set objFolders = myFolder.subfolders
for each objFolder2 in objfolders
doFolder objfolder2
next
end sub

Hope this helps.

Doug

>-----Original Message-----
>Hello,
>
>I need to delete files in a certain folder by current
date minus 2.
>
>I do not know how to do this - I've searched the archive
and the web....
>
>All suggestions will be greatly appreciated.
>
>Thanks in advance,
>Bill Burke
>
>.
>

Re: Delete Files by date by Torgeir

Torgeir
Wed May 26 11:29:35 CDT 2004

Bill Burke wrote:

> I need to delete files in a certain folder by current date minus 2.
>
> I do not know how to do this - I've searched the archive and the web....
Hi

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

Newsgroups: microsoft.public.scripting.wsh
Date: 2002-10-07 08:12:33 PST
http://groups.google.com/groups?selm=3DA1A19B.DF9B06D7%40hydro.com



--
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/community/scriptcenter/default.mspx

Re: Delete Files by date by Torgeir

Torgeir
Wed May 26 11:32:03 CDT 2004

Doug Schumann wrote:

> Try this -
>
> dtCheck = Dateadd("d",-2,date)
>
> set objFileSys = createobject
> ("scripting.filesystemobject")
> set objFolder = objfilesys.GetFolder
> ("c:\SomeFolder\OtherFolder\")
>
> doFolder objFolder
>
> sub doFolder(myFolder)
> set objFiles = myFolder.files
> for each objfile in objFiles
> if objfile.datelastmodified < dtcheck then
> objfile.delete
Hi

You should not do the file delete while you still are looping through
a file collection returned from the File System Object (FSO). The
collection may get mixed up. Create an array of the file objects to
avoid this. See my other post in his thread for an example...



--
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/community/scriptcenter/default.mspx