Skip to content

Instantly share code, notes, and snippets.

@mharris717
Created October 20, 2011 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mharris717/1301571 to your computer and use it in GitHub Desktop.
Save mharris717/1301571 to your computer and use it in GitHub Desktop.
Copy file to subdirs
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