Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Copy Folders Locally From Network

Posted on 2010-11-08
5
Medium Priority
?
262 Views
Last Modified: 2012-06-27
I want to run this from a command line  

cscript.exe //nologo copy.vbs "source" "destination"

I need the code for copy.vbs that can take the source that I type in and copy it to the destination that I type in.  I need the copy.vbs script to use my input on the command line as the variable for a copy folder vbscript.

Does anyone know how to do this?

Thanks
Carlos
0
Comment
Question by:BrianmKirsch
  • 3
5 Comments
 
LVL 14
ID: 34090350
Not sure how to do that in VBs, but it's Very simple in batch:

::Begin Batch Script
::Script Name: DoCopy.bat
XCopy "%~1" "%~2" /Z /Y
:: End batch script

You would write at the command line:

DoCopy.bat "Source" "destination"

However it really does beg the question, why don't you simply type this at the command prompt:

XCopy "Source" "Destination" /z /Y

Or better yet if the system is vista/2kgor 7. Use robocopy instead of xcopy.
0
 

Author Comment

by:BrianmKirsch
ID: 34090435
Thank you for your post but it has to be VB.  I am using it in MDT 2010 in a task sequence and have not been able to get anything but vbscript to work.  
0
 
LVL 8

Accepted Solution

by:
GundogTrainer earned 2000 total points
ID: 34091618
Attached is a simple code for copying a folder (not file specific):

There is no error checking but it should be a starting place.
dim filesys, sourcefolder, CmdArgs, strSrcFolder, strTargetFolder
set cmdArgs = wscript.arguments
if cmdArgs.count<>2 then 
 wscript.echo "requires 2 parameters"
 wscript.quit(0)
end if
strSrcFolder=cmdArgs(0)
strTargetFolder=cmdArgs(1)

set filesys = CreateObject ("Scripting.FileSystemObject")
set sourcefolder = filesys.GetFolder(strSrcFolder)
sourcefolder.Copy(strTargetFolder) 'target folder

Open in new window

0
 

Author Comment

by:BrianmKirsch
ID: 34092349
Thanks
I will try it and let you know.

Alternatively, there is no need for more answers as I wrote a Powershell one and tested it successfully while waiting on an answer.
0
 

Author Comment

by:BrianmKirsch
ID: 34098760
That VB script worked thank you so much!

If anyone wants a powershell one copy this easy code into a text and save it as Copy.ps1.

usage = powershell.exe -file copy.ps1 "source" "destination"
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!

Question has a verified solution.

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

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

782 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