RSMTECH_KC
asked on
How do I make this script run silently?
Hi,
My company uses a lot of automated faxing and our sent items folder on the server becomes very large rather quickly. I am currently using this script to clear out all items older than 30 days. The script works well. The only problem is that every time the script is run it requires my interaction. I would like to set this to run automatically as a scheduled task so that I do not have to manually run and click yes for every item being deleted. Or is there a better script to use for this?
Start of script
========================== ========== ========== ========== =
Const Active = True
Const sSource = "c:\fax\sent items"
Const MaxAge = 30 'days
Const Recursive = True
Checked = 0
Deleted = 0
Set oFSO = CreateObject("Scripting.Fi leSystemOb ject")
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
========================== ========== ========== ========== =
End of script
Thanks in advance!
My company uses a lot of automated faxing and our sent items folder on the server becomes very large rather quickly. I am currently using this script to clear out all items older than 30 days. The script works well. The only problem is that every time the script is run it requires my interaction. I would like to set this to run automatically as a scheduled task so that I do not have to manually run and click yes for every item being deleted. Or is there a better script to use for this?
Start of script
==========================
Const Active = True
Const sSource = "c:\fax\sent items"
Const MaxAge = 30 'days
Const Recursive = True
Checked = 0
Deleted = 0
Set oFSO = CreateObject("Scripting.Fi
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
==========================
End of script
Thanks in advance!
How do I make this script run silently?
tell it to be quiet :)
tell it to be quiet :)
remove all
WScript.Echo ...
lines
WScript.Echo ...
lines
or add //b on command line
wscript //b c:\myvbs\myscript.vbs
have a look at parameters
http://msdn.microsoft.com/en-us/library/xazzc41b(v=VS.85).aspx
wscript //b c:\myvbs\myscript.vbs
have a look at parameters
http://msdn.microsoft.com/en-us/library/xazzc41b(v=VS.85).aspx
ASKER
@it_saige
I tried your script but get an error referring to Line: 22 Char: 3
@HainKurt
I made these changes and ran on a test folder and it worked...however it deletes everything, not just files older than 30 days.
I tried your script but get an error referring to Line: 22 Char: 3
@HainKurt
I made these changes and ran on a test folder and it worked...however it deletes everything, not just files older than 30 days.
Try:
-saige-
Const Active = True
Const sSource = "c:\fax\sent items"
Const MaxAge = 30 '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)
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
If Active Then oFile.Delete
Next
if not Recursive then Exit Sub
For Each oSubfolder In oFldr.Subfolders
CheckFolder(oSubfolder)
Next
End Sub
HTH,-saige-
ASKER
For some reason it is still deleting all files in the folder. Not just those older than 30 days.
"For some reason it is still deleting all files in the folder. Not just those older than 30 days."
this is another question, not related to the original post :)
this is another question, not related to the original post :)
try
If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then Deleted = Deleted + 1
WScript.Echo verb & oFile.Path & """"
If Active Then oFile.Delete
End If
-->
If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then
Deleted = Deleted + 1
WScript.Echo verb & oFile.Path & """"
If Active Then oFile.Delete
End If
If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then Deleted = Deleted + 1
WScript.Echo verb & oFile.Path & """"
If Active Then oFile.Delete
End If
-->
If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then
Deleted = Deleted + 1
WScript.Echo verb & oFile.Path & """"
If Active Then oFile.Delete
End If
ASKER
Still not working. I might look at doing something else?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found another solution and answered my own question.
Open in new window
HTH,-saige-