How do I pass Parameters to a vbscript program?
Posted on 2007-07-20
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)
Dim fso, f
SET fso = CreateObject("ScriptINg.FileSystemObject")
SET f = fso.GetFile(filespec)
CreationDate = f.DateCreated
SET fso = CreateObject("Scripting.FileSystemObject")