Recursively Copy Directory And Contents With Ruby

Posted by Weston Ganger on December 03, 2015

I was writing a script and wanted to copy a directory and all its folders and contents.

Thankfully its ruby so its a very simple solution

# if your not using Rails require fileutils
require 'fileutils'

FileUtils.cp_r "path/to/my_source_folder/.", "path/to/my_destination_folder"

Dont get tricked, Notice the . in the source location, you would expect that to be a * but it doesn’t work like that.

Add verbose: true to the method if you want to see whats going on.

Related External Links:

Posted in Rails and Tagged with ruby 

Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts