Solved

Copy Folders Locally From Network

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
drawing animated level bar based on numbers 3 97
Visual Studio 2005 text editor 10 38
Prevent user closing word document opened with VB6 6 74
Help me. 3 54
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 …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

773 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