[thelist] Re: Deleting files in folder

James Hardy evolt at weeb.biz
Mon May 23 10:48:39 CDT 2005


Sam Carter wrote:

> Forgot to mention - Windows 2003 server.
>
> Sam Carter wrote:
>
>> Looking for an "easy" automated way to delete files in a folder that 
>> are more than 3 weeks old.
>>
>> Suggestions appreciated.
>>
>>
>>
>
>
Why not use wsh, vbscript and the scripting.filesystemobject - should 
all be available on a standard win2k3 install

something like (WARNING!!! not tested!!!):

set objFso=createObject("scripting.filesystemobject")
folder = "c:\thisFolder" 'or whatever - you could even use prompt() to 
enter it in each time
set objFolder = fso.getFolder(folder)
for each file in objFolder
    if dateDiff("d", file.dateCreated, now) > 21 then file.delete
next
set objfolder=nothing
set objFSO=nothing

There is also a file.dateLastModified property if that is more appropriate

-- 
James Hardy



More information about the thelist mailing list