?
Solved

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

Posted on 2005-03-07
3
Medium Priority
?
1,501 Views
Last Modified: 2008-01-09
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
Comment
Question by:jamieschaller
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 13482609
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
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13483782
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
 
LVL 22

Accepted Solution

by:
JesterToo earned 2000 total points
ID: 13483968
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question