Solved

How to Robocopy using vbs script?

Posted on 2004-04-27
5
4,866 Views
Last Modified: 2012-05-04
Can anyone show an example of vbs script to copy or move
files using robocopy in place of bat file?
0
Comment
Question by:leokuz
[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
5 Comments
 
LVL 1

Expert Comment

by:jangeador
ID: 10930921
I am not sure what you mean by robocopy, however, you can use the filesystem object to move and copy files with vbscript. Here is an example:

Sub ManipFiles
   Dim fso, f1, f2, s
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f1 = fso.CreateTextFile("c:\testfile.txt", True)
   Response.Write "Writing file <br>"
   ' Write a line.
   f1.Write ("This is a test.")
   ' Close the file to writing.
   f1.Close
   Response.Write "Moving file to c:\tmp <br>"
   ' Get a handle to the file in root of C:\.
   Set f2 = fso.GetFile("c:\testfile.txt")
   ' Move the file to \tmp directory.
   f2.Move ("c:\tmp\testfile.txt")
   Response.Write "Copying file to c:\temp <br>"
   ' Copy the file to \temp.
   f2.Copy ("c:\temp\testfile.txt")
   Response.Write "Deleting files <br>"
   ' Get handles to files' current location.
   Set f2 = fso.GetFile("c:\tmp\testfile.txt")
   Set f3 = fso.GetFile("c:\temp\testfile.txt")
   ' Delete the files.
   f2.Delete
   f3.Delete
   Response.Write "All done!"
End Sub
0
 
LVL 4

Expert Comment

by:lpzCoville
ID: 10932124
If by robocopy you are referring to this prhttp://www.ss64.com/nt/robocopy.html then I think you are saying that you want to control this .exe from VBS, right?  if so, pleaease atke a look at this PAQ http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20814533.html#9864331
0
 
LVL 3

Accepted Solution

by:
Level10Access earned 500 total points
ID: 10935072
He means Robocopy from the Windows Resource Kit.

Well, considering there's so many options for the Robocopy executable, i can only show you how to execute robocopy with your parameters. Heres the options for robocopy:
http://www.ss64.com/nt/robocopy.html
 Save the code below as a .VBS file:

set objShell=CreateObject("Wscript.Shell")
objShell.Run("C:\PATHTORESOURCEKIT\robocopy.exe -OPTIONS")

replace PathToResourcekit with the path the robocopy and OPTIONS with your custom options from the page i gave you above.

Enjoy!


0
 
LVL 1

Author Comment

by:leokuz
ID: 10936436
I appologize for the confusion to everyone, but you Level10Access got me right! I just tested your code and it works excellent! :)  Thank you.
0
 
LVL 1

Author Comment

by:leokuz
ID: 10936529
I forgot to ask you question though, when I typed  C:\Program Files\Windows Resource Kits\Tools\robocopy.exe as a path I  received an error box, something like could not find file specified, and only after I made folder C:\Tools and dropped copy of robocopy.exe into that folder, changed the robocopy path to C:\Tools\robocopy.exe then it started to work. Why it couldn't find "roby" in first case? Thanks upfront.
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add projects t working set in maven 2 64
collection output issue 9 91
programming a polycom voip phone 3 82
Batch rename files sequentially and move 7 50
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

739 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