• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1503
  • Last Modified:

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! :)
0
jamieschaller
Asked:
jamieschaller
1 Solution
 
Erick37Commented:
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))
0
 
gecko_au2003Commented:
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 :)
0
 
JesterTooCommented:
Your shell command would look something like this...

   Call Shell("cmd /c cscript \\Level1\Level2\Folder1\CopyFolders.vbs  "  & chr(34) & Trim(strProjectName) & chr(34))

This will allow for embedded spaces within the new project name (and corresponding folder name).

Then, your script would contain...

   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("\\Level1\Level2\Folder1\" & objArgs(0))

   '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\" & objArgs(0)

HTH,
Lynn

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now