Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I make this script run silently?

Posted on 2011-03-18
12
Medium Priority
?
483 Views
Last Modified: 2012-05-11
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.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
=========================================================
End of script

Thanks in advance!
0
Comment
Question by:RSMTECH_KC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 34

Expert Comment

by:it_saige
ID: 35167784
Try:
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
		End If
	Next

	if not Recursive then Exit Sub
	For Each oSubfolder In oFldr.Subfolders
		CheckFolder(oSubfolder)
	Next
End Sub

Open in new window

HTH,

-saige-
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 35168034
How do I make this script run silently?

tell it to be quiet :)
0
 
LVL 59

Expert Comment

by:HainKurt
ID: 35168064
remove all

WScript.Echo ...

lines
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 59

Expert Comment

by:HainKurt
ID: 35168078
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
0
 
LVL 1

Author Comment

by:RSMTECH_KC
ID: 35168904
@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.
0
 
LVL 34

Expert Comment

by:it_saige
ID: 35169107
Try:
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

Open in new window

HTH,

-saige-
0
 
LVL 1

Author Comment

by:RSMTECH_KC
ID: 35169258
For some reason it is still deleting all files in the folder.  Not just those older than 30 days.
0
 
LVL 59

Expert Comment

by:HainKurt
ID: 35169952
"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 :)
0
 
LVL 59

Expert Comment

by:HainKurt
ID: 35169960
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
0
 
LVL 1

Author Comment

by:RSMTECH_KC
ID: 35180658
Still not working.  I might look at doing something else?
0
 
LVL 1

Accepted Solution

by:
RSMTECH_KC earned 0 total points
ID: 35183138
Found another solution.
0
 
LVL 1

Author Closing Comment

by:RSMTECH_KC
ID: 35221226
I found another solution and answered my own question.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question