R
Richard
Hi All,
I wrote a simple test a techiques I'll apply in an app I'm going start
shortly. One thing my test did is: -- -- open a non-existent file for
appending,
-- populate it
-- close it
-- open it for reading, expecting automatic closure when reading ended
-- looped through file printing its line to STDOUT
-- attempted to delete the file -- got "Permission denied -
TestOutput.txt (Errno::EACCES)"
I tested it under SciTE.
The relevant code fragment is listed below. I think the problem is
that the file is in the process of being closed by WindowsXP-Pro when
the delete request hits the OS and the OS complains.
If that's correct, all I have to do is write some loop that naps and
re-attempts the deletion until successful. Is there better approach,
or is my analysis wrong in the first place?
********* Code fragment ****************
puts "\nDisplaying the content of #{fno}:"
puts "Opening #{fno}'"
File.open(fno, "r") do |file| # Open for reading
while sLine = file.gets
puts sLine
end
end # File will be closed automantically when scope of "do" exited
puts "#{fno} closed"
puts "\nDeleting #{fno}"
File.delete(fno)
*************************************************
TIA,
Richard
I wrote a simple test a techiques I'll apply in an app I'm going start
shortly. One thing my test did is: -- -- open a non-existent file for
appending,
-- populate it
-- close it
-- open it for reading, expecting automatic closure when reading ended
-- looped through file printing its line to STDOUT
-- attempted to delete the file -- got "Permission denied -
TestOutput.txt (Errno::EACCES)"
I tested it under SciTE.
The relevant code fragment is listed below. I think the problem is
that the file is in the process of being closed by WindowsXP-Pro when
the delete request hits the OS and the OS complains.
If that's correct, all I have to do is write some loop that naps and
re-attempts the deletion until successful. Is there better approach,
or is my analysis wrong in the first place?
********* Code fragment ****************
puts "\nDisplaying the content of #{fno}:"
puts "Opening #{fno}'"
File.open(fno, "r") do |file| # Open for reading
while sLine = file.gets
puts sLine
end
end # File will be closed automantically when scope of "do" exited
puts "#{fno} closed"
puts "\nDeleting #{fno}"
File.delete(fno)
*************************************************
TIA,
Richard