From: agemoagemo@... Date: 2003-10-31T02:57:13+09:00 Subject: Re: Problem with seeking in existing files. --- Warren Brown wrote: > Morgan, > > > I'm trying to write a program that will be writing > > data to an existing file, that will not > necessarily > > be done in the physical file order. I used mode > > 'ab+' to open the file, as only the 'a' modes > allow > > writing without changing the existing file. > > It sounds like what you really want is to open > the file with a mode > of 'r+b'. This allows reading and writing of the > file without > truncating the file (like 'w+b'). As you mentioned, > a mode of 'ab' > opens the file for writing only (at end of file). > To open for reading > and writing (at end of file) you would need a mode > of 'a+b'. I believe > a mode of 'ab+' is technically incorrect on most > platforms, although it > may work on some. Well, I don't know about technical incorrectness, but mode 'a+b' is identified as an illegal access mode, wheras 'ab+' will execute. 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. -Morgan. __________________________________ Do you Yahoo!? Exclusive Video Premiere - Britney Spears http://launch.yahoo.com/promos/britneyspears/