Link to home
Start Free TrialLog in
Avatar of jamieschaller
jamieschaller

asked on

Need to pass a variable to an external vbscript to manipulate files

Okay so I am having a senior moment. I need to pass a value to a vbscript so that the script can use the value to rename copied files. I have the following line of code that copies a set of default folders and files -->

Call Shell("cmd /c cscript \\Level1\Level2\Folder1\CopyFolders.vbs")

I have the following code in CopyFolders.vbs

Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")

'First we need to create the new project folder
objFSO.CreateFolder("\\Level1\Level2\Folder1\NewProject")

'Next we are going to copy the contents of the default folder into the new project folder.
objFSO.CopyFolder "\\Level1\Level2\Folder1\Folder2\Default", "\\Level1\Level2\Folder1\NewProject"

Now what I need for someone with more sense that I can muster at this point, is to tell me what to write so that I can pass a variable value into the "NewProject" value in the create folder line. Then what do I need to add to the Call Shell ... line to pass that value. Basically, what I am trying to do in a nutshell --> A user creates a new project record in a visual basic program, then on successful save of that record the vbscript file is executed to create the mandatory folders and files required for that project. I need the vbscript to name the new project file (new destination file) the Project's acronym that is received from the saved record (or more easily a text box on a form) and then copy the default subfolders and files to that newly renamed folder.

I need an answer as soon as possible, because we are wanting to deploy tomorrow, if I can resolve this issue. So to those that will help me or answer this question I say THANK YOU and I bow to your superiority! :)
Avatar of Erick37
Erick37
Flag of United States of America image

With the Wscript.Arguments object:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsproarguments.asp

Example:

Dim objFSO
Dim objArgs

Set objFSO = CreateObject("Scripting.FileSystemObject")

'Get the array of args passed in
Set objArgs = WScript.Arguments

'First we need to create the new project folder
objFSO.CreateFolder("c:\" & objArgs(0))
not sure if this is an alternative but you could write to a text file in visual basic and read from it in the vb script :) using FSO :)
ASKER CERTIFIED SOLUTION
Avatar of JesterToo
JesterToo
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