So your program is essentially like this:
f = File.open("foo.dat", "w")
f.puts "BKP_DATE: "
...
IO.readlines(fullpath).each do |line|
f.puts line
end
f.close
f.puts "BKP_DATE: "
...
IO.readlines(fullpath).each do |line|
f.puts line
end
f.close
You tried to close
the same File
object twice.
I don't know the whole structure of your program, but perhaps you should instantiate the File
object inside your backup
method. And this is how you should write it in Ruby (:
File.open("foo.dat", "w") {|f|
f.puts "BKP_DATE: "
IO.readlines(fullpath).each do |line|
f.puts line
end
} # f is automatically closed here
If you really need to open the file outside your backup
method, I think what you need at the end of bakcup
is @f.flush
rather than @f.close
. This would be an acceptable solution for you provided that you don't open hundreds of files in your script.
As for pausing, try sleep 5.0