Link to home
Start Free TrialLog in
Avatar of DonFreeman
DonFreemanFlag for United States of America

asked on

How do I pass Parameters to a vbscript program?

I have a small vbscript program that I inherited that is used to delete archive and log files from a directory based on date.  All the directories and "older than"  numbers are hard coded.  I would like to pass parameters to this file but can't figure out how to do it.  %1 doesn't work.  I ordered two vbscript books but they won't be in for awhile and I'd like to keep going.  Can I set a variable in a calling program and read it?  How do I accomplish this?   I want to pass two things.  A directory name and a number that represents the max number of days to retain.  The code is included below.  

myDir = "F:\oracle\backups\NEDARCD\Recent_Exports\"
WScript.Echo " Current Directory is F:\oracle\backups\NEDARCD\Recent_Exports\"

SET filesystem = CreateObject("Scripting.FileSystemObject")
SET folder = filesystem.GetFolder(myDir)

SET filecollection = folder.Files

FOR Each file IN filecollection
     IF DateDiff("d", CreationDate(myDir & file.name), Now()) > 6 THEN
       WScript.Echo DateDif("d", CreationDate(myDir & file.name),Now()) & " " & file.name & " " & CreationDate(myDir & file.name)
       DeleteFiles(myDir & file.name)
     END IF
NEXT

SET filesystem=nothing
SET folder=nothing
SET filecollection=nothing


FUNCTION CreationDate(filespec)
  Dim fso, f
  SET fso = CreateObject("ScriptINg.FileSystemObject")
  SET f = fso.GetFile(filespec)
  CreationDate = f.DateCreated
END Function

FUNCTION DeleteFiles(filespec)
  DIM fso
  SET fso = CreateObject("Scripting.FileSystemObject")
  fso.DeleteFile(filespec)
END Function

ASKER CERTIFIED SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DonFreeman

ASKER

So wscript.arguments(0) would be my first argument and that would be my directory name and then wscript.arguments(1) would be my second one right?.   I am quitting for the day but I'll get back on it Monday and when I get it working I'll award your points.  It looks like a solid solution.  Thanks!
Yes. WScript.Arguments.Count is the count of arguments passed. so you can check that too to make sure 2 arguments were indeed passed.
I am still working on this...