Solved

Copy Folders Locally From Network

Posted on 2010-11-08
5
259 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
[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
5 Comments
 
LVL 12
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 500 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

Independent Software Vendors: 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

Suggested Solutions

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

710 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