robocopy

A Ruby wrapper for Robocopy with Rake tasks!

Installation

Add this line to your application's Gemfile:

gem 'robocopy'

And then execute:

$ bundle

Or install it yourself as:

$ gem install robocopy

Usage

Obviously, require this gem at the top of your rakefile

require 'robocopy'

Robocopy requires only the source and destination paths. And most copies work fine with a full directory mirror.

robocopy :copy do |cmd|
  cmd.source = 'bin'
  cmd.destination = '//some/output/path'
  cmd.mirror
end

Although, occassionally you have to pick and choose files from the source

robocopy :copy do |cmd|
  cmd.source = 'bin'
  cmd.destination = '//some/output/path'
  cmd.files = [ 'a.dll', 'a.bin', 'a.exe' ]
end

It's just an array, so feel free to experiment with FileList and Dir.glob wildcards, pathmap, and plain map.

cmd.files = FileList['bin/**/*']
              .exclude('**/*.dummy')
              .map { |file| File.basename file }

Or exclude files and/or directories

cmd.exclude_files = [ '*.pdb' ]
cmd.exclude_dirs = [ 'examples' ]

There are a handful of logging options available

cmd.tee
cmd.log = 'copy.log'
# or
cmd.log_append = 'copy.log'

And, finally, the option to dry run the copy (I like this for development)

cmd.dryrun

The task is executed using the Ruby system method. That returns true on non-zero exit codes. But, robocopy has non-zero successful exit codes! So the output is kind of re-evaluated like this

system "<your-command>" || $?.exitstatus < 8

It's not lovely and it doesn't tell you much about what happened, but it's good enough to allow your Rake task to pass.