I don't have time to write you a complete script. Basically you need to do
something like this:
On Error Resume Next
strFolder="f:\data"
Call DeleteOldFiles(strFolder)
wscript.quit 'end main script
Sub DeleteOldFiles(strFolder)
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFolder=objFSO.GetFolder(strFolder)
Set colFiles=objFolder.Files
For Each file In colFiles
If Int(DateDiff("d",file.DateLastModified,Now)) >= 60 Then
WScript.Echo "Deleting " & file & " (" &_
file.DateLastModified & ")"
objFSO.DeleteFile file,True
If Err.Number<>0 Then
WScript.Echo "**Failed to delete " & file & ". Error# " &_
Err.Number & " " & Err.Description & "**"
End If
End If
Next
Set colSubs=-objFolder.SubFolders
For Each subFldr In colSubs
Call DeleteOldFiles(subFldr)
next
end sub
'end of script
I strongly suggest you pick up one or two books on scripting. I always
recommend VBScript, WMI and ADSI Unleashed by Don Jones as a good tutorial.
My WSH and VBScript Core: TFM is a complete language reference with
real-world and practical examples of every object, function, method,
property and statement you are likely to need in VBScript.
--
Jeffery Hicks
Microsoft PowerShell MVP
http://www.scriptinganswers.com
http://www.powershellcommunity.org
Now Available: WSH and VBScript Core: TFM
Coming Soon: Windows PowerShell: TFM 2nd Ed.
"po_boy" <poboy@discussions.microsoft.com> wrote in message
news:0C9E58D5-98D5-4535-B406-B5DD7EAF1998@microsoft.com...
> Thanks Jeffery, but that is the problem. I am not versed enought in
> functions
> to make it delete the sub-folders and or files.
>
> "Jeffery Hicks [MVP]" wrote:
>
>> See if this s get you in the right direction.
>>
>> On Error Resume Next
strFolder="f:\data"
>> Set objFSO=CreateObject("Scripting.FileSystemObject")
>> Set objFolder=objFSO.GetFolder(strFolder)
>> Set colFiles=objFolder.Files
>> For Each file In colFiles
>> If Int(DateDiff("d",file.DateLastModified,Now)) >= 60 Then
>> WScript.Echo "Deleting " & file & " (" &_
>> file.DateLastModified & ")"
>> objFSO.DeleteFile file,True
>> If Err.Number<>0 Then
>> WScript.Echo "**Failed to delete " & file & ". Error# " &_
>> Err.Number & " " & Err.Description & "**"
>> End If
>> End If
>> Next
>> 'end of script
>>
>> This script finds all files in F:\Data that are > 60 days old based on
>> date
>> last modified and deletes them. You could take this code and create a
>> function so you could recurse through subfolders.
>>
>> --
>> Jeffery Hicks
>> Microsoft PowerShell MVP
>> http://www.scriptinganswers.com
>> http://www.powershellcommunity.org
>>
>> Now Available: WSH and VBScript Core: TFM
>> Coming Soon: Windows PowerShell: TFM 2nd Ed.
>>
>> "po_boy" <poboy@discussions.microsoft.com> wrote in message
>> news
DFA0136-97B9-4D00-B847-0614060EF44F@microsoft.com...
>> >I have some files and folders under C:\LogFiles. This folder has many
>> > subfolders and files. I need to find an easy way to delete the files or
>> > folders(subfolder) that are older than X days. Most scripts only do a
>> > folder
>> > and files but not a group and since I am not that good with scripts it
>> > is
>> > not
>> > working well for my needs. Please assist.
>>