Created
March 30, 2015 22:55
-
-
Save michaelfward/ada4279fa7eaa5b476f7 to your computer and use it in GitHub Desktop.
Copy contents of multiple files (passed as a command line argument of a file containing the paths) into a single file
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
#!/bin/ruby | |
def getfile(path) | |
content = [] | |
content[0] = "from: #{path}\n\n\n" #hopefully makes the output easier to read | |
fd = File.open(path.chomp, "r") | |
fd.each_line {|x| content.push(x)} | |
content.push("\n\n") | |
$destination_output.push(content) | |
puts "successfully got #{path}" | |
end | |
def usage | |
puts "writefiles [file with paths] [file to write to]" | |
exit | |
end | |
usage unless ARGV.length == 2 | |
fd = File.open(ARGV[0], "r") | |
destination = File.open(ARGV[1], "w") | |
$destination_output = [] | |
paths = [] | |
fd.each_line {|x| paths.push(x)} | |
paths.each do |x| | |
getfile(x) | |
end | |
def write_strs(arr) | |
str = "" | |
arr.each do |x| | |
str << x unless x.class == [].class | |
end | |
end | |
$destination_output.each do |arr| | |
if arr.class == [].class | |
s = write_strs(arr) | |
destination.write(s) | |
elsif arr.class == "".class | |
destination.write(arr) | |
else | |
puts "Whats this? #{arr.class}\n#{arr}\n\n(end content)" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment