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



Send Me A Message

I would love to get in touch and talk about your next project. Feel free to send a message and I will get back to you shortly.

Get Connected