Question concerning ruby file access
- From: Stefan Salewski <mail@xxxxxxxxxxxx>
- Date: Thu, 30 Oct 2008 00:14:57 +0000 (UTC)
Question concerning ruby file access from a novice:
I have seen following code fragment from
http://www.rubycentral.com/pickaxe/tut_io.html
File.open("testfile", "r") do |aFile|
# ... process the file
end
Advantage of this notation is that file is automatically closed when do
loop terminates -- maybe by an exception with Process.exit.
But how do I test in this notation that the file with name "testfile"
really exits (and opening was successful). In an multi-tasking
environment another process may delete the file just before this
statement is executed.
Or in other words: I want to print a text like "File with filename
"testfile" does not exist" when opening failed.
Best regards
Stefan Salewski
.
- Follow-Ups:
- Re: Question concerning ruby file access
- From: Peña, Botp
- Re: Question concerning ruby file access
- From: Ken Bloom
- Re: Question concerning ruby file access
- From: Sebastian Hungerecker
- Re: Question concerning ruby file access
- Prev by Date: which is right place to submit bugs
- Next by Date: Re: Question concerning ruby file access
- Previous by thread: which is right place to submit bugs
- Next by thread: Re: Question concerning ruby file access
- Index(es):
Relevant Pages
|