Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


tweak my script

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,62076
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> tweak my script
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 tweak my script - 7/1/2008 4:01:23 AM   
  jack.bauer

 

Posts: 3
Score: 0
Joined: 7/1/2008
Status: offline
new to vbs (and programming).
wrote this script to search for directories older than 30days old and delete them. it works.
Now before it deletes them, i'd like it to see an output of the folder name and the last modified date.
i tried doing this with wscript.echo but as you can see had to comment it out as it displayed each one in a message box. how can i tweak my script?

Option Explicit

Const intDaysOld = 30
Dim ArgObj, Var
Set ArgObj = WScript.Arguments
Var = ArgObj(0)
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFolder : Set objFolder = objFSO.GetFolder(Var)
Dim objSubFolder
For Each objSubFolder In objFolder.SubFolders
   'WScript.Echo objSubFolder.DateLastModified
   If DateValue(objSubFolder.DateLastModified) < DateValue(Now() - intDaysOld) Then
      ' WScript.Echo objSubFolder.DateLastModified
     'WScript.Echo objSubFolder.Name
       objSubFolder.Delete True
   End If
Next
 
 
Post #: 1
 
 RE: tweak my script - 7/1/2008 4:08:52 AM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi jack.bauer,

start your script from a command line like

  C> cscript <your.vbs> "thePathAsArg"

the MessageBoxes are caused by wscript.exe.

Regards

ehvbs

(in reply to jack.bauer)
 
 
Post #: 2
 
 RE: tweak my script - 7/1/2008 4:20:50 AM   
  jack.bauer

 

Posts: 3
Score: 0
Joined: 7/1/2008
Status: offline
ah wicked. thanks.

now i want to use prompt to confirm i want to delete the folders.
i did this:

If WScript.Popup("Do you want to delete these directories?",0,"Confirm",36) = 6 Then
   'WScript.Echo "boom!"
Else
   wscript.echo "fizz"
End If

but it returns saying
F:\FIP\vbs\deleteOldFolders_CMD.vbs(17, 1) Microsoft VBScript runtime error: Object doesn't support this property or met
hod: 'WScript.Popup'

(in reply to jack.bauer)
 
 
Post #: 3
 
 RE: tweak my script - 7/1/2008 5:27:50 AM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
WScript (the script host object privided by wscript and cscript.exe) is different
from the WScript Object you use the get a Shell (same name, different 'persons').
If you look carefully at the .Popup sample from the VBScript Docs:

Dim WshShell, BtnCode
Set WshShell = WScript.CreateObject("WScript.Shell")
BtnCode = WshShell.Popup("Do you feel alright?", 7, "Answer This Question:", 4 + 32)

you'll see that

  If WScript.Popup("Do you want to delete these directories?",0,"Confirm",36) = 6 Then

should be

  If WshShell.Popup("Do you want to delete these directories?",0,"Confirm",36) = 6 Then

of course, you need to create this WshShell object before you can use it.

(in reply to jack.bauer)
 
 
Post #: 4
 
 RE: tweak my script - 7/1/2008 5:39:32 AM   
  jack.bauer

 

Posts: 3
Score: 0
Joined: 7/1/2008
Status: offline
according to my book, i create the object like this?

 
set WshShell = WScript.CreateObject("WScript.Shell")

(in reply to jack.bauer)
 
 
Post #: 5
 
 RE: tweak my script - 7/1/2008 5:55:59 AM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
yes.
(which book - I'm just interested)
if you are a pedantic paranoiac like me, you'll use

Set oWSH = CreateObject( "WScript.Shell" )

(1) "Set" - VBScript isn't case sensitive, but I think it's better to be consistent

(2) "oWSH" - I prefere to indicate the data type of a variable with a short prefix;
     shorter variable names reduce the risk of typos

(3) The Script Host WScript object provides a .CreateObject method, but the language
     has a CreatObject function too. See the VBScript docs for the differences. I prefer
     the function, because it can be used in .hta/.html code, where the WScript object
     (and its methods, notably .Sleep) aren't available

(4) I think white space (around parentheses and operators) improves readability

(in reply to jack.bauer)
 
 
Post #: 6
 
 RE: tweak my script - 7/2/2008 2:47:15 AM   
  Rischip


Posts: 468
Score: 2
Joined: 3/26/2007
Status: offline
http://www.microsoft.com/technet/scriptcenter/guide/sas_wsh_lubv.mspx?mfr=true

Compare CreatOjbect VS. Wscript.CreateObject
Scroll to bottom

_____________________________

Rischip
Author of - The Grim Linker

(in reply to ehvbs)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> tweak my script Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts