I am currently looking for a software/web development job preferably as a Rails-based developer.
Please email me at weston@westonganger.com. Thanks in advance for any leads!

Recursively Copy Directory And Contents With Ruby

Posted by Weston Ganger

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:

Article Topic:Software Development - Rails

Date:December 03, 2015

Recommended Posts