Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Copy Folders Locally From Network

Posted on 2010-11-08
5
Medium Priority
?
261 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

721 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