Rails

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 


Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts