Created
August 23, 2012 21:23
-
-
Save dmcclory/3441996 to your computer and use it in GitHub Desktop.
Copying the contents of one directory to another
This file contains hidden or 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
# you want to recursively copy the contents of one folder to another | |
# but you don't want to actually copy the first folder into the second | |
#3 ways to try to copy the contents of one directory to another: | |
require 'pathname' | |
require 'fileutils' | |
include FileUtils | |
p = Pathname.new('input') | |
o = Pathname.new('output') | |
# 1) | |
p.children.each do |c| # this works | |
cp_r c, o | |
end | |
# 2) | |
cp_r p.children, o # this works, and is a little simpler than #1 | |
# 3) | |
cp_r p, o # this doesn't work, | |
# it copies the input directory, as well as it's contents into output | |
# result looks like: output/input/CONTENTS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment