I am nill with scripting. I found this script on the net and I would like to
delete files older than 2 days from a folder. Please correct this for me. I
really appreciate.

Option Explicit
on error resume next
Dim oFSO
Dim sDirectoryPath
Dim oFolder
Dim oFileCollection
Dim oFile
Dim iDaysOld

'Customize values here to fit your needs
iDaysOld = 2
Set oFSO = CreateObject("Scripting.FileSystemObject")
sDirectoryPath = "FolderName here. Can be UNC path like \\MyServer\MyFolder"
set oFolder = oFSO.GetFolder(sDirectoryPath)
set oFileCollection = oFolder.Files

'Walk through each file in this folder collection.
'If it is older than 3 weeks (21) days, then delete it.
For each oFile in oFileCollection
If oFile.DateLastModified < (Date() - iDaysOld) Then
oFile.Delete(True)
End If
Next

'Clean up
Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing


Thank you very much in advance.

RE: delete files in a folder that are certain days old by ESP

ESP
Tue Nov 08 11:38:05 CST 2005

The Scripting Guys have a nice lil' page on this. Very easy to follow :-)

http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1104.mspx


ESP





"WILDPACKET" wrote:

> I am nill with scripting. I found this script on the net and I would like to
> delete files older than 2 days from a folder. Please correct this for me. I
> really appreciate.
>
> Option Explicit
> on error resume next
> Dim oFSO
> Dim sDirectoryPath
> Dim oFolder
> Dim oFileCollection
> Dim oFile
> Dim iDaysOld
>
> 'Customize values here to fit your needs
> iDaysOld = 2
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> sDirectoryPath = "FolderName here. Can be UNC path like \\MyServer\MyFolder"
> set oFolder = oFSO.GetFolder(sDirectoryPath)
> set oFileCollection = oFolder.Files
>
> 'Walk through each file in this folder collection.
> 'If it is older than 3 weeks (21) days, then delete it.
> For each oFile in oFileCollection
> If oFile.DateLastModified < (Date() - iDaysOld) Then
> oFile.Delete(True)
> End If
> Next
>
> 'Clean up
> Set oFSO = Nothing
> Set oFolder = Nothing
> Set oFileCollection = Nothing
> Set oFile = Nothing
>
>
> Thank you very much in advance.
>

RE: delete files in a folder that are certain days old by WILDPACKET

WILDPACKET
Tue Nov 08 13:06:05 CST 2005

Thank you ESP for your response. I'll look into it.

Regards,



"ESP" wrote:

> The Scripting Guys have a nice lil' page on this. Very easy to follow :-)
>
> http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1104.mspx
>
>
> ESP
>
>
>
>
>
> "WILDPACKET" wrote:
>
> > I am nill with scripting. I found this script on the net and I would like to
> > delete files older than 2 days from a folder. Please correct this for me. I
> > really appreciate.
> >
> > Option Explicit
> > on error resume next
> > Dim oFSO
> > Dim sDirectoryPath
> > Dim oFolder
> > Dim oFileCollection
> > Dim oFile
> > Dim iDaysOld
> >
> > 'Customize values here to fit your needs
> > iDaysOld = 2
> > Set oFSO = CreateObject("Scripting.FileSystemObject")
> > sDirectoryPath = "FolderName here. Can be UNC path like \\MyServer\MyFolder"
> > set oFolder = oFSO.GetFolder(sDirectoryPath)
> > set oFileCollection = oFolder.Files
> >
> > 'Walk through each file in this folder collection.
> > 'If it is older than 3 weeks (21) days, then delete it.
> > For each oFile in oFileCollection
> > If oFile.DateLastModified < (Date() - iDaysOld) Then
> > oFile.Delete(True)
> > End If
> > Next
> >
> > 'Clean up
> > Set oFSO = Nothing
> > Set oFolder = Nothing
> > Set oFileCollection = Nothing
> > Set oFile = Nothing
> >
> >
> > Thank you very much in advance.
> >

RE: delete files in a folder that are certain days old by WILDPACKET

WILDPACKET
Tue Nov 08 13:15:07 CST 2005

This article talks about deleting oldar than specified date.

In my scenario I want to schedule the files to be deleted which are older
than 2 days using a similar script.








ESP" wrote:

> The Scripting Guys have a nice lil' page on this. Very easy to follow :-)
>
> http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1104.mspx
>
>
> ESP
>
>
>
>
>
> "WILDPACKET" wrote:
>
> > I am nill with scripting. I found this script on the net and I would like to
> > delete files older than 2 days from a folder. Please correct this for me. I
> > really appreciate.
> >
> > Option Explicit
> > on error resume next
> > Dim oFSO
> > Dim sDirectoryPath
> > Dim oFolder
> > Dim oFileCollection
> > Dim oFile
> > Dim iDaysOld
> >
> > 'Customize values here to fit your needs
> > iDaysOld = 2
> > Set oFSO = CreateObject("Scripting.FileSystemObject")
> > sDirectoryPath = "FolderName here. Can be UNC path like \\MyServer\MyFolder"
> > set oFolder = oFSO.GetFolder(sDirectoryPath)
> > set oFileCollection = oFolder.Files
> >
> > 'Walk through each file in this folder collection.
> > 'If it is older than 3 weeks (21) days, then delete it.
> > For each oFile in oFileCollection
> > If oFile.DateLastModified < (Date() - iDaysOld) Then
> > oFile.Delete(True)
> > End If
> > Next
> >
> > 'Clean up
> > Set oFSO = Nothing
> > Set oFolder = Nothing
> > Set oFileCollection = Nothing
> > Set oFile = Nothing
> >
> >
> > Thank you very much in advance.
> >

RE: delete files in a folder that are certain days old by ESP

ESP
Tue Nov 08 15:40:15 CST 2005

Exactly. Using the "NOW" command will specify today's date/time/etc..., this
will happen.

ESP

"WILDPACKET" wrote:

> This article talks about deleting oldar than specified date.
>
> In my scenario I want to schedule the files to be deleted which are older
> than 2 days using a similar script.
>
>
>
>
>
>
>
>
> ESP" wrote:
>
> > The Scripting Guys have a nice lil' page on this. Very easy to follow :-)
> >
> > http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1104.mspx
> >
> >
> > ESP
> >
> >
> >
> >
> >
> > "WILDPACKET" wrote:
> >
> > > I am nill with scripting. I found this script on the net and I would like to
> > > delete files older than 2 days from a folder. Please correct this for me. I
> > > really appreciate.
> > >
> > > Option Explicit
> > > on error resume next
> > > Dim oFSO
> > > Dim sDirectoryPath
> > > Dim oFolder
> > > Dim oFileCollection
> > > Dim oFile
> > > Dim iDaysOld
> > >
> > > 'Customize values here to fit your needs
> > > iDaysOld = 2
> > > Set oFSO = CreateObject("Scripting.FileSystemObject")
> > > sDirectoryPath = "FolderName here. Can be UNC path like \\MyServer\MyFolder"
> > > set oFolder = oFSO.GetFolder(sDirectoryPath)
> > > set oFileCollection = oFolder.Files
> > >
> > > 'Walk through each file in this folder collection.
> > > 'If it is older than 3 weeks (21) days, then delete it.
> > > For each oFile in oFileCollection
> > > If oFile.DateLastModified < (Date() - iDaysOld) Then
> > > oFile.Delete(True)
> > > End If
> > > Next
> > >
> > > 'Clean up
> > > Set oFSO = Nothing
> > > Set oFolder = Nothing
> > > Set oFileCollection = Nothing
> > > Set oFile = Nothing
> > >
> > >
> > > Thank you very much in advance.
> > >

Re: delete files in a folder that are certain days old by Rob

Rob
Wed Nov 09 13:51:27 CST 2005

ESP wrote:
> Exactly. Using the "NOW" command will specify today's date/time/etc..., this
> will happen.
>
> ESP
>
> "WILDPACKET" wrote:
>
>
>>This article talks about deleting oldar than specified date.
>>
>>In my scenario I want to schedule the files to be deleted which are older
>>than 2 days using a similar script.
>>
>>
>>
>>
>>
>>
>>
>>
>>ESP" wrote:
>>
>>
>>>The Scripting Guys have a nice lil' page on this. Very easy to follow :-)
>>>
>>>http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1104.mspx
>>>
>>>
>>>ESP
>>>
>>>
>>>
>>>
>>>
>>>"WILDPACKET" wrote:
>>>
>>>
>>>>I am nill with scripting. I found this script on the net and I would like to
>>>>delete files older than 2 days from a folder. Please correct this for me. I
>>>>really appreciate.
>>>>
>>>>Option Explicit
>>>>on error resume next
>>>> Dim oFSO
>>>> Dim sDirectoryPath
>>>> Dim oFolder
>>>> Dim oFileCollection
>>>> Dim oFile
>>>> Dim iDaysOld
>>>>
>>>>'Customize values here to fit your needs
>>>> iDaysOld = 2
>>>> Set oFSO = CreateObject("Scripting.FileSystemObject")
>>>> sDirectoryPath = "FolderName here. Can be UNC path like \\MyServer\MyFolder"
>>>> set oFolder = oFSO.GetFolder(sDirectoryPath)
>>>> set oFileCollection = oFolder.Files
>>>>
>>>>'Walk through each file in this folder collection.
>>>>'If it is older than 3 weeks (21) days, then delete it.
>>>> For each oFile in oFileCollection
>>>> If oFile.DateLastModified < (Date() - iDaysOld) Then
>>>> oFile.Delete(True)
>>>> End If
>>>> Next
>>>>
>>>>'Clean up
>>>> Set oFSO = Nothing
>>>> Set oFolder = Nothing
>>>> Set oFileCollection = Nothing
>>>> Set oFile = Nothing
>>>>
>>>>
>>>>Thank you very much in advance.
>>>>
Hi,

I was looking for the answer a week ago and found FORFILES on my W2k3
server.

It's part of the Resource Kit since Win98 and part of the OS in W2k3.

Look at
http://www.microsoft.com/technet/prodtechnol/windowsserver2003/library/ServerHelp/9660fea1-65c7-48cf-b466-204ba159381e.mspx
to read:

To list all of the files older than 100 days on drive C:, type:
forfiles /p c:\ /s /m*.* /dt-100 /c"cmd /c echo @file : date >= 100
days"

Maybe a .CMD script or a .vbs script using Run() is the easy way.

Greetings,
Rob

Re: delete files in a folder that are certain days old by ESP

ESP
Thu Nov 10 13:32:42 CST 2005

Thx ! Another great resource !!
ESP



"Rob Moerland" wrote:

> ESP wrote:
> > Exactly. Using the "NOW" command will specify today's date/time/etc..., this
> > will happen.
> >
> > ESP
> >
> > "WILDPACKET" wrote:
> >
> >
> >>This article talks about deleting oldar than specified date.
> >>
> >>In my scenario I want to schedule the files to be deleted which are older
> >>than 2 days using a similar script.
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>ESP" wrote:
> >>
> >>
> >>>The Scripting Guys have a nice lil' page on this. Very easy to follow :-)
> >>>
> >>>http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1104.mspx
> >>>
> >>>
> >>>ESP
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>"WILDPACKET" wrote:
> >>>
> >>>
> >>>>I am nill with scripting. I found this script on the net and I would like to
> >>>>delete files older than 2 days from a folder. Please correct this for me. I
> >>>>really appreciate.
> >>>>
> >>>>Option Explicit
> >>>>on error resume next
> >>>> Dim oFSO
> >>>> Dim sDirectoryPath
> >>>> Dim oFolder
> >>>> Dim oFileCollection
> >>>> Dim oFile
> >>>> Dim iDaysOld
> >>>>
> >>>>'Customize values here to fit your needs
> >>>> iDaysOld = 2
> >>>> Set oFSO = CreateObject("Scripting.FileSystemObject")
> >>>> sDirectoryPath = "FolderName here. Can be UNC path like \\MyServer\MyFolder"
> >>>> set oFolder = oFSO.GetFolder(sDirectoryPath)
> >>>> set oFileCollection = oFolder.Files
> >>>>
> >>>>'Walk through each file in this folder collection.
> >>>>'If it is older than 3 weeks (21) days, then delete it.
> >>>> For each oFile in oFileCollection
> >>>> If oFile.DateLastModified < (Date() - iDaysOld) Then
> >>>> oFile.Delete(True)
> >>>> End If
> >>>> Next
> >>>>
> >>>>'Clean up
> >>>> Set oFSO = Nothing
> >>>> Set oFolder = Nothing
> >>>> Set oFileCollection = Nothing
> >>>> Set oFile = Nothing
> >>>>
> >>>>
> >>>>Thank you very much in advance.
> >>>>
> Hi,
>
> I was looking for the answer a week ago and found FORFILES on my W2k3
> server.
>
> It's part of the Resource Kit since Win98 and part of the OS in W2k3.
>
> Look at
> http://www.microsoft.com/technet/prodtechnol/windowsserver2003/library/ServerHelp/9660fea1-65c7-48cf-b466-204ba159381e.mspx
> to read:
>
> To list all of the files older than 100 days on drive C:, type:
> forfiles /p c:\ /s /m*.* /dt-100 /c"cmd /c echo @file : date >= 100
> days"
>
> Maybe a .CMD script or a .vbs script using Run() is the easy way.
>
> Greetings,
> Rob
>

Re: delete files in a folder that are certain days old by ai

ai
Fri Jan 13 16:04:02 CST 2006

This would work great for what I need, however, when I run this command the
date selection (/dt-100 or /d t-100) doesn't work. If I put in an exact
date it works well, but I need it to delete all files older than 100 days,
and need to run it monthly without having to enter a new date every month.

To list all of the files older than 100 days on drive C:, type:
> forfiles /p c:\ /s /m*.* /dt-100 /c"cmd /c echo @file : date >= 100
> days"

Am I doing something wrong?


"Rob Moerland" wrote:

> ESP wrote:
> > Exactly. Using the "NOW" command will specify today's date/time/etc..., this
> > will happen.
> >
> > ESP
> >
> > "WILDPACKET" wrote:
> >
> >
> >>This article talks about deleting oldar than specified date.
> >>
> >>In my scenario I want to schedule the files to be deleted which are older
> >>than 2 days using a similar script.
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>ESP" wrote:
> >>
> >>
> >>>The Scripting Guys have a nice lil' page on this. Very easy to follow :-)
> >>>
> >>>http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1104.mspx
> >>>
> >>>
> >>>ESP
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>"WILDPACKET" wrote:
> >>>
> >>>
> >>>>I am nill with scripting. I found this script on the net and I would like to
> >>>>delete files older than 2 days from a folder. Please correct this for me. I
> >>>>really appreciate.
> >>>>
> >>>>Option Explicit
> >>>>on error resume next
> >>>> Dim oFSO
> >>>> Dim sDirectoryPath
> >>>> Dim oFolder
> >>>> Dim oFileCollection
> >>>> Dim oFile
> >>>> Dim iDaysOld
> >>>>
> >>>>'Customize values here to fit your needs
> >>>> iDaysOld = 2
> >>>> Set oFSO = CreateObject("Scripting.FileSystemObject")
> >>>> sDirectoryPath = "FolderName here. Can be UNC path like \\MyServer\MyFolder"
> >>>> set oFolder = oFSO.GetFolder(sDirectoryPath)
> >>>> set oFileCollection = oFolder.Files
> >>>>
> >>>>'Walk through each file in this folder collection.
> >>>>'If it is older than 3 weeks (21) days, then delete it.
> >>>> For each oFile in oFileCollection
> >>>> If oFile.DateLastModified < (Date() - iDaysOld) Then
> >>>> oFile.Delete(True)
> >>>> End If
> >>>> Next
> >>>>
> >>>>'Clean up
> >>>> Set oFSO = Nothing
> >>>> Set oFolder = Nothing
> >>>> Set oFileCollection = Nothing
> >>>> Set oFile = Nothing
> >>>>
> >>>>
> >>>>Thank you very much in advance.
> >>>>
> Hi,
>
> I was looking for the answer a week ago and found FORFILES on my W2k3
> server.
>
> It's part of the Resource Kit since Win98 and part of the OS in W2k3.
>
> Look at
> http://www.microsoft.com/technet/prodtechnol/windowsserver2003/library/ServerHelp/9660fea1-65c7-48cf-b466-204ba159381e.mspx
> to read:
>
> To list all of the files older than 100 days on drive C:, type:
> forfiles /p c:\ /s /m*.* /dt-100 /c"cmd /c echo @file : date >= 100
> days"
>
> Maybe a .CMD script or a .vbs script using Run() is the easy way.
>
> Greetings,
> Rob
>