读取txt文件的路径,并使用ruby将这些文件复制到新目录
实际上,我正在使用以下代码查找文件中的路径:读取txt文件的路径,并使用ruby将这些文件复制到新目录,ruby,Ruby,实际上,我正在使用以下代码查找文件中的路径: files_to_read = Dir['This/is/a_path/.sln'] files_to_read.each do |file_name| array = [] # regex for the line where the source path is stored regex = /(\.\.\\[^"]+)/ File.open(file_name) do |f| f.each_line do |line
files_to_read = Dir['This/is/a_path/.sln']
files_to_read.each do |file_name|
array = []
# regex for the line where the source path is stored
regex = /(\.\.\\[^"]+)/
File.open(file_name) do |f|
f.each_line do |line|
regex.match(line) do |matches|
array << matches[1]
File.open("This/is/a_path/tmp.txt", 'w+') {|f| f.write array.join("\n")}
end
end
end
end
end
现在我想将这些c源代码复制到另一个目录“destination_dir”。类似这样的内容(称为“伪代码”):
File.open(“This/is/a_path/tmp.txt,'r')do|f|
f、 每行FileUtils.cp(,“destination\u dir”)
知道如何使用ruby吗?我不确定我是否遵循了这个问题,但你是说这个吗
tmp_file = File.read "This/is/a_path/tmp.txt"
tmp_file.lines.each do |file_name|
FileUtils.cp(file_name, "destination_dir")
end
File.open("This/is/a_path/tmp.txt", 'r') do |f|
f.each_line FileUtils.cp(<the_c_sources>, "destination_dir")
tmp_file = File.read "This/is/a_path/tmp.txt"
tmp_file.lines.each do |file_name|
FileUtils.cp(file_name, "destination_dir")
end