Solved

Copy Folders Locally From Network

Posted on 2010-11-08
5
254 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 11

Expert Comment

by:Ben Personick
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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 …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now