Robocopy Scripts for Directory Opus

RoboCopy, short for Robust File Copy Utility, is great for synchronizing directories, making a quick backup of a USB drive, or just refreshing a backup with files that have recently changed. I know you can do much of the same thing with the Synchronize panel within Opus, but I like to be able to launch RoboCopy within a DOS script and navigate away without having to wait for Opus to do its thing.

If your not familiar with RoboCopy, it's a DOS Utility from Microsoft, which comes with Windows now but was originally available in the Windows Server 2003 Resource Kit, http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

From the Help File:

If needed: How to use buttons and scripts from this forum

I have two scripts that I use almost everyday that I'll share:

1) RoboCopy everything NEWER from Source to Destination including all sub folders

<?xml version="1.0"?>
<button display="both" separate="yes">
	<label>RoboCopy /e /xo</label>
	<tip>RoboCopy /e /xo</tip>
	<icon1>87</icon1>
	<function type="batch">
		<instruction>@echo off</instruction>
		<instruction>color 0b</instruction>
		<instruction>echo --------------------------------------------------</instruction>
		<instruction>echo D I R E C T O R Y  O P U S - R O B O C O P Y </instruction>
		<instruction>echo RoboCopy Script for DOpus v9.x</instruction>
		<instruction>echo --------------------------------------------------</instruction>
		<instruction>echo. </instruction>
		<instruction>echo robocopy {sourcepath$|noterm} {destpath$|noterm} /e /xo /w:1 /r:1 &gt;c:\~temp.cmd</instruction>
		<instruction>echo pause&gt;&gt;c:\~temp.cmd</instruction>
		<instruction>call c:\~temp.cmd</instruction>
	</function>
</button>

The switches in the command line explained

  • /e - everything including all subfolders
  • /xo - exclude anything older
  • /w:1 - if the file is in use, wait 1 second before retrying
  • /r:1 - number of retries

2) RoboCopy MOVE everything NEWER from Source to Destination including all sub folders

<?xml version="1.0"?>
<button display="both">
	<label>RoboCopy /move /e /xo</label>
	<tip>RoboCopy /move /e /xo</tip>
	<icon1>87</icon1>
	<function type="batch">
		<instruction>@echo off</instruction>
		<instruction>color 0b</instruction>
		<instruction>echo --------------------------------------------------</instruction>
		<instruction>echo D I R E C T O R Y  O P U S - R O B O C O P Y </instruction>
		<instruction>echo RoboCopy Script for DOpus v9.x</instruction>
		<instruction>echo --------------------------------------------------</instruction>
		<instruction>echo. </instruction>
		<instruction>echo robocopy {sourcepath$|noterm} {destpath$|noterm} /e /move /xo /w:1 /r:1 &gt; c:\~temp.cmd</instruction>
		<instruction>echo pause &gt;&gt; c:\~temp.cmd</instruction>
		<instruction>call c:\~temp.cmd</instruction>
	</function>
</button>

The switches are the same as the first example with the addition of

  • /move

When RoboCopy completes it presents a summery (see snapshot below) of the number of files copied, skipped, etc so I've built in a pause so the window doesn't close before you have a chance to see it. You can always remove the pause or replace with a delay such as ping -n 5 127.0.0.1 > nul

You can also use /MIR to mirror directories (be careful), /LOG to create logfiles. Check the documentation or RoboCopy /? to see extended information of all the switches.

In my opinion, Directory Opus is the greatest, but when is comes to large copy or move jobs, sometimes it's better to pass it to DOS.

Oh, yes, it does work \\unc to \\unc

Hope someone finds this useful.

~ Sam






1 Like

Hi, that's nice.

How to change the behaviour to only copy the selected files/folders on the Source?

Thanks

Paulo

Using this method you can target spacific folders within a lister. Is uses the current selected lister as the source, and the destination as the target.

Yes but it seems to copy every folder in the source lister, and that's nice anyway. But I would like to specifically select which folders in the source lister to copy to the destination...

Paulo

  • MtDew12oz,

    Is there a reason the button echos the commands into a temporary batch file and then runs that, instead of simply running the commands?

    Opus automatically generates temporary batch files for the (external) commands in MS-DOS Batch type buttons.

    This much simpler button should have the same result:

    robocopy {sourcepath$|noterm} {destpath$|noterm} /e /move /xo /w:1 /r:1
    pause
    

    It also doesn't leave a temp file sitting in C:\ (Opus deletes its temp batch files automatically). Perhaps most importantly, there is no problem running the simplified button several times as each one will get its own batch file instead of reusing the one in C:\ (which may still be in use).

  • pauloffb,

    You just need to change sourcepath to filepath to do what you want:

    robocopy {filepath$|noterm} {destpath$|noterm} /e /move /xo /w:1 /r:1
    pause
    

    If multiple folders (or files) are selected then Opus will run robocopy once per folder (or file). That should give you what you're after.

. Leo

I want a button to complete a one-way sync with a directory on my hosted site. How can I do it directly, without Robocopy.

I want to specify the source and destination in the script (they're fixed), and then it would be nice to add on lister close run this first, or a time based option.

You're asking about how to not use Robocopy in a thread about using Robocopy...

You can use Opus's Copy UpdateAll command to do what you want. Have a look in the manual at the arguments that the Copy command takes. If you need further help please start a thread in the Help & Support forum.

Ah there were two good reasons

  1. You know your way around and if there was a thread on my request you'd point me to it directly, and,
  2. My request is so close to what Robocopy does that you may have answered it directly here

I had a look in the manual but didn't find good examples of building commands. Copy update all is the key obviously. Am off to Help and Support now.

Thanks

Sorry to bump an old thread but I would be really grateful for some help on this one.
I made a button the way Leo describes like this:

robocopy {filepath$|noterm} {destpath$|noterm} /e /move /xo /w:1 /r:1
pause

and it's (kind of) working. The problem I can't get around is that it only copies the files and not the folder. If I have a folder, C:\Test, with two files in it, test1.txt and test2.txt. I want to copy booth the folder and the files to g:\Test2 so the the result is g:\Test2\Test\test1.txt, test2.txt. However, when I select the folder C:\Test and push the button only the files test1.txt and text2.txt get copied over, not the folder C:\Test.

This will do that:

@nofilenamequoting
robocopy "{filepath$|noterm}" "{destpath$}{filepath$|nopath|noterm}" /e /move /xo /w:1 /r:1
pause

(If you want it to copy instead of move, remove the /move argument from all the examples.)

1 Like

Worked like a charm. Thank you very much. :slight_smile:

1 Like