![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | delete files older than x days from a folder and its subfolders looking for a script or something will let me schedule it. Only plan to do it once a year so might have lots of log files. Each log is less than 2 MB. Thanks. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: delete files older than x days from a folder and its subfolders "Chris" <Chris@xxxxxx> wrote in message news:5EEB2BC9-A84B-41C4-B646-24ED83D7B8A3@xxxxxx Quote: > looking for a script or something will let me schedule it. Only plan to > do > it once a year so might have lots of log files. Each log is less than 2 > MB. > > Thanks. satisfied that it deletes the right files! Const Active = False Const sSource = "d:\My Files" Const MaxAge = 10 'days Const Recursive = True Checked = 0 Deleted = 0 Set oFSO = CreateObject("Scripting.FileSystemObject") if active then verb = "Deleting """ Else verb = "Old file: """ CheckFolder oFSO.GetFolder(sSource) WScript.echo if Active then verb = " file(s) deleted" Else verb = " file(s) would be deleted" WScript.Echo Checked & " file(s) checked, " & Deleted & verb Sub CheckFolder (oFldr) For Each oFile In oFldr.Files Checked = Checked + 1 If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then Deleted = Deleted + 1 WScript.Echo verb & oFile.Path & """" If Active Then oFile.Delete End If Next if not Recursive then Exit Sub For Each oSubfolder In oFldr.Subfolders CheckFolder(oSubfolder) Next End Sub |
My System Specs![]() |
| | #3 (permalink) |
| | Re: delete files older than x days from a folder and its subfolder The script is GREAT!! Just what I need. Thanks!! "Pegasus (MVP)" wrote: Quote: > > "Chris" <Chris@xxxxxx> wrote in message > news:5EEB2BC9-A84B-41C4-B646-24ED83D7B8A3@xxxxxx Quote: > > looking for a script or something will let me schedule it. Only plan to > > do > > it once a year so might have lots of log files. Each log is less than 2 > > MB. > > > > Thanks. > Here you go. Make sure to run the script with active=false until you're > satisfied that it deletes the right files! > > Const Active = False > Const sSource = "d:\My Files" > Const MaxAge = 10 'days > Const Recursive = True > > Checked = 0 > Deleted = 0 > > Set oFSO = CreateObject("Scripting.FileSystemObject") > if active then verb = "Deleting """ Else verb = "Old file: """ > CheckFolder oFSO.GetFolder(sSource) > > WScript.echo > if Active then verb = " file(s) deleted" Else verb = " file(s) would be deleted" > WScript.Echo Checked & " file(s) checked, " & Deleted & verb > > Sub CheckFolder (oFldr) > For Each oFile In oFldr.Files > Checked = Checked + 1 > If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then > Deleted = Deleted + 1 > WScript.Echo verb & oFile.Path & """" > If Active Then oFile.Delete > End If > Next > > if not Recursive then Exit Sub > For Each oSubfolder In oFldr.Subfolders > CheckFolder(oSubfolder) > Next > End Sub > > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: delete files older than x days from a folder and its subfolder "Chris" <Chris@xxxxxx> wrote in message news:FE9E9E65-99F6-4CD8-BF05-EA207BE38D50@xxxxxx Quote: > The script is GREAT!! Just what I need. Thanks!! > > "Pegasus (MVP)" wrote: |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| copy text files only from all subfolders within a folderto a another folder | VB Script | |||
| List files in folder with subfolders at top? | Vista file management | |||
| Delete Files Older than 6 Months | PowerShell | |||
| Delete files which are not modified in 30 days | PowerShell | |||
| Deleting all files older than one hour in a folder | PowerShell | |||