Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBScript to run a robocopy command

Posted on 2010-08-22
7
Medium Priority
?
11,291 Views
Last Modified: 2012-06-21
Hi All,

I'm trying to run a robocopy command within a VBScript which isn't producing an error, but isn't completing the required file copy either. I need to use VBScript as a list of folders must be iterated through.

On Error Resume Next
Set oShell=WScript.CreateObject("WScript.Shell")
Set objFSO = Wscript.CreateObject("Scripting.FileSystemObject")
WScript.Run("robocopy" & " " & Chr(34) & "C:\source\folder one" & Chr(34) & " " & Chr(34) & "C:\dest\folder one" & Chr(34) & " " & "/e /xo /mir /zb /R:5 /W:5 /LOG+:" & Chr(34) & "logs\folder one.log" & Chr(34))

Open in new window


This code works if the source and destination dirnames lack spaces. Any ideas?
0
Comment
Question by:paulkramer
[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
7 Comments
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 2000 total points
ID: 33498037
Use
oShell.Run
instead of Wscript.run
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 2000 total points
ID: 33498050
Firstly tho - take out that beginning line - on error resume next - you're masking any errors, preventing you from telling what's not working.
Try this:
Set oShell=WScript.CreateObject("WScript.Shell")
'(Do you even need FSO?) Set objFSO = Wscript.CreateObject("Scripting.FileSystemObject")
strSource = Chr(34) & "C:\source\folder one" & Chr(34) 
strTarget = Chr(34) & "C:\dest\folder one" & Chr(34) 
strParms = " /e /xo /mir /zb /R:5 /W:5 /LOG+:" & Chr(34) & "C:\logs\folder one.log" & Chr(34)
oShell.Run "robocopy " & strSource & " " & strTarget & strParms

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33507211
sirbounty....long time no see....I hope you're keeping well.

The original script looks like it would have worked, only if the WScript.Run was changed to oShell.Run, but either way, sirbounty's is a bit more managable.

Regards,

Rob.
0
 

Expert Comment

by:tmac603
ID: 34306018
use oShell.Run "%comspec% /k robocopy " & strSource & " " & strTarget & strParms to keep the Cmd box open if the script is erring
0
 
LVL 7

Expert Comment

by:CitizenRon
ID: 35451250
If, like me, you're not a big fan of using a bunch of & Chr(34) & (the ASCII code for a double-quote) then you can just insert a double-quote mark inside a string using a double double-quote ("") when you create the string.

an edit of sirbounty's rewrite using double double-quotes would look like this:
Set oShell=WScript.CreateObject("WScript.Shell")
'(Do you even need FSO?) Set objFSO = Wscript.CreateObject("Scripting.FileSystemObject")
strSource = """C:\source\folder one"""
strTarget = """C:\dest\folder one"""
strParms = " /e /xo /mir /zb /R:5 /W:5 /LOG+:""C:\logs\folder one.log"""
oShell.Run "robocopy " & strSource & " " & strTarget & strParms

Open in new window

Yes, there's THREE double-quotes in there in some spots and only a single actual "double double-quote" but that's because a string is always started with a double-quote and ends with a double-quote.  The "triple double-quotes" are actually a "single double-quote" immediately followed by a "double double-quote" to start the string with a double-quote at the beginning of it and vice-versa to end the string with a double-quote at the end of it.

How's that for technological double-speak?
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Suggested Courses

618 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