Created
October 20, 2011 16:18
-
-
Save mharris717/1301571 to your computer and use it in GitHub Desktop.
Copy file to subdirs
This file contains 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
task :copy_to_subdirs do | |
### CHANGE THESE TWO VARIABLES | |
### USE FORWARD SLASHES IN THE DIRECTORY NAMES | |
directory_with_files_to_copy = "c:/code/test_dir9" | |
dir_containing_subdirs = "c:/code/test_dir9/some_dir" | |
source_files = Dir["#{directory_with_files_to_copy}/*"].select { |x| FileTest.file?(x) } | |
subdirs = Dir["#{dir_containing_subdirs}/*"].select { |x| FileTest.directory?(x) } | |
source_files.each do |source_file| | |
subdirs.each do |subdir| | |
FileUtils.cp source_file,subdir | |
end | |
end | |
end | |
task :make_subdirs do | |
## the file should be one line per dir | |
list_of_dirs = "c:/code/test_dir9/list_of_dirs.txt" | |
## this is where you're creating the directories | |
base_dir = "c:/code/test_dir9/some_dir" | |
### DON'T EDIT BELOW HERE | |
dirs = File.read(list_of_dirs).split("\n").map { |x| x.strip }.select { |x| x != '' } | |
dirs.each do |d| | |
d = "#{base_dir}/#{d}" | |
FileUtils.mkdir(d) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment