7stud said:
File.foreach("data.txt") do |line|
#look for something in line
end
Here is what I originally wrote, and what I just tried. Am I missing
something obvious? The first one duplicates the lines, and the second
one does nothing. (doesn't save the changes)
def change_texture_paths
File.open(Dir.glob(ENV['HOME'] + "/*.ma").first, "r+") do |file|
file.grep( /setAttr ".fileTextureName" -type "string"/ ) do |line|
texture_file_path = line[52..-2]
texture_file_name = texture_file_path.split("\/").last
line = " setAttr \".fileTextureName\" -type \"string\"
\"" + ENV['HOME'] + "/include/" + texture_file_name + "\n"
file.print line
end
end
File.foreach(Dir.glob(ENV['HOME'] + "/*.ma").first, "r+") do |line|
if (line =~ /setAttr ".fileTextureName" -type "string"/ )
texture_file_path = line[52..-2]
texture_file_name = texture_file_path.split("\/").last
line = " setAttr \".fileTextureName\" -type \"string\"
\"" + ENV['HOME'] + "/include/" + texture_file_name + "\n"
file.print line
end
end
end