How to Robocopy using vbs script?

Can anyone show an example of vbs script to copy or move
files using robocopy in place of bat file?
Who is Participating?

Improve company productivity with a Business Account.Sign Up

Level10AccessConnect With a Mentor Commented:
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:
 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.


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.
   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.
   Response.Write "All done!"
End Sub
If by robocopy you are referring to this pr 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
leokuzAuthor Commented:
I appologize for the confusion to everyone, but you Level10Access got me right! I just tested your code and it works excellent! :)  Thank you.
leokuzAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.