On Fri, 31 Oct 2003 02:57:13 +0900, agemoagemo / yahoo.com wrote:
> Using mode 'rb+' seems to produce the behavior I need... when the file
> exists. When it doesn't, however, it produces:
> 
> in `initialize': No such file or directory - "new.zip" (Errno::ENOENT)
> 
> Given the alternative, I'd be quite happy to work around it by testing
> for the presence of a file, and creating a new one if it doesn't exist...
> but I haven't yet found a simple way to test for this.

Do:

begin
  File.open(filename, "rb+") { |f| ... }
rescue Errno::ENOENT
  File.open(filename, "wb").close
  retry
end

-austin
--
austin ziegler    * austin / halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.10.30
                                         * 13.34.38