DonFreeman
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_Ex ports\"
WScript.Echo " Current Directory is F:\oracle\backups\NEDARCD\ Recent_Exp orts\"
SET filesystem = CreateObject("Scripting.Fi leSystemOb ject")
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.Fi leSystemOb ject")
SET f = fso.GetFile(filespec)
CreationDate = f.DateCreated
END Function
FUNCTION DeleteFiles(filespec)
DIM fso
SET fso = CreateObject("Scripting.Fi leSystemOb ject")
fso.DeleteFile(filespec)
END Function
myDir = "F:\oracle\backups\NEDARCD
WScript.Echo " Current Directory is F:\oracle\backups\NEDARCD\
SET filesystem = CreateObject("Scripting.Fi
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.Fi
SET f = fso.GetFile(filespec)
CreationDate = f.DateCreated
END Function
FUNCTION DeleteFiles(filespec)
DIM fso
SET fso = CreateObject("Scripting.Fi
fso.DeleteFile(filespec)
END Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes. WScript.Arguments.Count is the count of arguments passed. so you can check that too to make sure 2 arguments were indeed passed.
ASKER
I am still working on this...
ASKER