Hi all,
There is folder we stored the backup files and we only need to keep 15 days
data. Is there a way to do this automatically to only keep data for 15 days?
windows 2003 R2 and files with extension .bak
Thank you.
Hi all,
There is folder we stored the backup files and we only need to keep 15 days
data. Is there a way to do this automatically to only keep data for 15 days?
windows 2003 R2 and files with extension .bak
Thank you.
You could write a batch file and run it in Windows scheduler.
@Echo off
del c:\FolderName\*.bak /Q
"ed" <ed@newsgroup> wrote in message
news:0F0B1239-DFDA-4537-AA6F-D5CED8E5214C@newsgroup
> Hi all,
>
> There is folder we stored the backup files and we only need to keep 15
> days
> data. Is there a way to do this automatically to only keep data for 15
> days?
>
> windows 2003 R2 and files with extension .bak
>
> Thank you.
"ed" <ed@newsgroup> said this in news item
news:0F0B1239-DFDA-4537-AA6F-D5CED8E5214C@newsgroupHere you go:
> Hi all,
>
> There is folder we stored the backup files and we only need to keep 15
> days
> data. Is there a way to do this automatically to only keep data for 15
> days?
>
> windows 2003 R2 and files with extension .bak
>
> Thank you.
'--------------------------------------------
'This script will delete files that were last
'updated "MaxAge" days ago.
'30.1.2009 FNL
'--------------------------------------------
Const Active = False
Const sSource = "d:\User 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"
end if
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
Set to four "const" statements at the start to suit your environment. I
recommend that you leave "active = false" until you're satisfied that the
script would do what you expect it to do. Remember to invoke it with
cscript.exe.
Thanks and tht's what I am looking for.
BTW, about the script, which extension should I save for the script and run
cscript.exe?
thank you.
"Pegasus [MVP]" wrote:
>
>
> "ed" <ed@newsgroup> said this in news item
> news:0F0B1239-DFDA-4537-AA6F-D5CED8E5214C@newsgroup>
> > Hi all,
> >
> > There is folder we stored the backup files and we only need to keep 15
> > days
> > data. Is there a way to do this automatically to only keep data for 15
> > days?
> >
> > windows 2003 R2 and files with extension .bak
> >
> > Thank you.
> Here you go:
>
> '--------------------------------------------
> 'This script will delete files that were last
> 'updated "MaxAge" days ago.
> '30.1.2009 FNL
> '--------------------------------------------
> Const Active = False
> Const sSource = "d:\User 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"
> end if
> 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
>
> Set to four "const" statements at the start to suit your environment. I
> recommend that you leave "active = false" until you're satisfied that the
> script would do what you expect it to do. Remember to invoke it with
> cscript.exe.
>
> .
>
It worked beautifully and THANK YOU and THANK YOU!
"ed" wrote:
> Thanks and tht's what I am looking for.
> BTW, about the script, which extension should I save for the script and run
> cscript.exe?
>
> thank you.
>
> "Pegasus [MVP]" wrote:
>
> >
> >
> > "ed" <ed@newsgroup> said this in news item
> > news:0F0B1239-DFDA-4537-AA6F-D5CED8E5214C@newsgroup> >
> > > Hi all,
> > >
> > > There is folder we stored the backup files and we only need to keep 15
> > > days
> > > data. Is there a way to do this automatically to only keep data for 15
> > > days?
> > >
> > > windows 2003 R2 and files with extension .bak
> > >
> > > Thank you.
> > Here you go:
> >
> > '--------------------------------------------
> > 'This script will delete files that were last
> > 'updated "MaxAge" days ago.
> > '30.1.2009 FNL
> > '--------------------------------------------
> > Const Active = False
> > Const sSource = "d:\User 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"
> > end if
> > 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
> >
> > Set to four "const" statements at the start to suit your environment. I
> > recommend that you leave "active = false" until you're satisfied that the
> > script would do what you expect it to do. Remember to invoke it with
> > cscript.exe.
> >
> > .
> >
Sorry to bother you again.
Do you have a script based on Last Accessed date? Thank you.
"Pegasus [MVP]" wrote:
>
>
> "ed" <ed@newsgroup> said this in news item
> news:0F0B1239-DFDA-4537-AA6F-D5CED8E5214C@newsgroup>
> > Hi all,
> >
> > There is folder we stored the backup files and we only need to keep 15
> > days
> > data. Is there a way to do this automatically to only keep data for 15
> > days?
> >
> > windows 2003 R2 and files with extension .bak
> >
> > Thank you.
> Here you go:
>
> '--------------------------------------------
> 'This script will delete files that were last
> 'updated "MaxAge" days ago.
> '30.1.2009 FNL
> '--------------------------------------------
> Const Active = False
> Const sSource = "d:\User 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"
> end if
> 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
>
> Set to four "const" statements at the start to suit your environment. I
> recommend that you leave "active = false" until you're satisfied that the
> script would do what you expect it to do. Remember to invoke it with
> cscript.exe.
>
> .
>
Thanks for the feedback. I get the impression that you worked out for
yourself that the correct file extension is .vbs.
You can use the following properties when comparing dates:
- .DateCreated
- .DateLastAccessed
- .DateLastModified
You need to find out for yourself how dependable the .LastAccessed property
is. Remember that files deleted with this script do *not* go into the
recycle bin. They are well and truly deleted.
"ed" <ed@newsgroup> said this in news item
news:8B1D25E1-0FC4-430D-B408-0DE572ED61C2@newsgroup
> Sorry to bother you again.
>
> Do you have a script based on Last Accessed date? Thank you.
>
> Do you have a script based on Last Accessed date?
plus search for sub-folders too
"ed" wrote:
> Sorry to bother you again.
>
> Do you have a script based on Last Accessed date? Thank you.
>
>
>
> "Pegasus [MVP]" wrote:
>
> >
> >
> > "ed" <ed@newsgroup> said this in news item
> > news:0F0B1239-DFDA-4537-AA6F-D5CED8E5214C@newsgroup> >
> > > Hi all,
> > >
> > > There is folder we stored the backup files and we only need to keep 15
> > > days
> > > data. Is there a way to do this automatically to only keep data for 15
> > > days?
> > >
> > > windows 2003 R2 and files with extension .bak
> > >
> > > Thank you.
> > Here you go:
> >
> > '--------------------------------------------
> > 'This script will delete files that were last
> > 'updated "MaxAge" days ago.
> > '30.1.2009 FNL
> > '--------------------------------------------
> > Const Active = False
> > Const sSource = "d:\User 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"
> > end if
> > 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
> >
> > Set to four "const" statements at the start to suit your environment. I
> > recommend that you leave "active = false" until you're satisfied that the
> > script would do what you expect it to do. Remember to invoke it with
> > cscript.exe.
> >
> > .
> >
Great for your reply.
Can we search the sub-folder too?
Thanks for your help.
"Pegasus [MVP]" wrote:
> Thanks for the feedback. I get the impression that you worked out for
> yourself that the correct file extension is .vbs.
>
> You can use the following properties when comparing dates:
> - .DateCreated
> - .DateLastAccessed
> - .DateLastModified
>
> You need to find out for yourself how dependable the .LastAccessed property
> is. Remember that files deleted with this script do *not* go into the
> recycle bin. They are well and truly deleted.
>
>
> "ed" <ed@newsgroup> said this in news item
> news:8B1D25E1-0FC4-430D-B408-0DE572ED61C2@newsgroup>
> > Sorry to bother you again.
> >
> > Do you have a script based on Last Accessed date? Thank you.
> >
>
> .
>
"ed" <ed@newsgroup> said this in news item
news:F9A8C02F-533D-453E-995E-03465E19BA38@newsgroupHmm. Did you consider the meaning of the four const statements in my code?> plus search for sub-folders too
>> Do you have a script based on Last Accessed date?
| Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Logon Script Causing Laptops To Hang - Problems in script? | Ben | VB Script | 5 | 07 Feb 2009 |
| problem passing args to script 'There is no script engine for file extenstion' | James | VB Script | 5 | 31 Oct 2008 |
| Include another script, keep variables in included script? | pschmidt | PowerShell | 14 | 18 Aug 2008 |
| Script file has 'OS Handle' error when run from script | Jay | PowerShell | 1 | 18 Sep 2007 |
| Can you drag-n-drop a file on top of a PS script to run the script? | Jen Taylor | PowerShell | 6 | 06 Apr 2007 |