Skip to content

Instantly share code, notes, and snippets.

@mikeobrien
Created August 1, 2010 18:08
Show Gist options
  • Save mikeobrien/503592 to your computer and use it in GitHub Desktop.
Save mikeobrien/503592 to your computer and use it in GitHub Desktop.
# robocopy.rb
class Robocopy
attr_accessor :source, :target, :excludeDirs, :includeFiles, :logPath
def run()
robocopy = "robocopy.exe " \
"\"#{@source}\" " \
"\"#{@target}\" " \
"/MIR " \
"/XD #{@excludeDirs} " \
"/IF #{@includeFiles} " \
"/LOG+:\"#{@logPath}\" " \
"/TEE"
errorHandler = \
lambda do |ok, res|
raise "Robocopy failed with exit " \
"code #{res.exitstatus}." \
if res.exitstatus > 8
end
sh robocopy, &errorHandler
end
end
def robocopy(*args, &block)
body = lambda { |*args|
rc = Robocopy.new
block.call(rc)
rc.run
}
Rake::Task.define_task(*args, &body)
end
# rakefile.rb
desc "Deploys the application."
robocopy :deploy => :build do |rc|
rc.source = "src/ProjectEuler.UI"
rc.target = "D:/Websites/euler.mikeobrien.net/wwwroot"
rc.excludeDirs = "obj"
rc.includeFiles = "*.dll *.pdb *.config *.asax *.ascx *.ashx " \
"*.aspx *.master *.htm *.html *.txt *.css " \
"*.gif *.jpg *.jpeg *.png *.xml *.js"
rc.logPath = "Robocopy.log"
end
@mikesigs
Copy link

Thanks for the robocopy task. I found it very helpful. But I do have one suggestion. Change line 8 from:
robocopy = "robocopy " \

to:

robocopy = "robocopy.exe " \

I just spent the last hour wondering why the sh robocopy command wasn't doing anything. Well, it turns out that since the robocopy.rb file is in the same folder as my Rakefile.rb it was interpreting the shell command as wanting to call the rb not the exe.

@mikeobrien
Copy link
Author

Nice catch, thx for pointing that out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment