P
Pokkai Dokkai
how can replace a text from all files in
"/home/user" directory and sub directories (tree)...
"/home/user" directory and sub directories (tree)...
Pokkai said:how can replace a text from all files in
"/home/user" directory and sub directories (tree)...
Try this:
Dir.glob('/Users/me/2testing/dir2/**/*') do |fname|
next if File.directory?(fname)
File.open("temp.txt", "w") do |temp_file|
IO.foreach(fname) do |line| #fname is from outer loop
new_line = line.gsub("hello world", "goodbye")
temp_file.print(new_line)
end
File.delete(fname)
File.rename("temp.txt", fname)
end
end
William said:This botched code bombs. Don't ever post untest code without
stating that it is untested code.
What you want a EULA(gy)?lol.
puts "Whiner!"Wayne said:My god... you ran code posted to a mailing list blindly?!?
I made that mistake... once.
~Wayne
Pokkai said:how can replace a text from all files in
"/home/user" directory and sub directories (tree)...
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.