Created
August 1, 2010 18:08
-
-
Save mikeobrien/503592 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
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
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.