realbasic-nug
[Top] [All Lists]

Re: Should I Delete to Overwrite?

To: REALbasic Network Users Group <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Should I Delete to Overwrite?
From: "Joseph J. Strout" <joe at realsoftware dot com>
Date: Fri, 30 Aug 2002 11:53:31 -0700
At 2:45 PM -0400 8/30/02, Charles Yeomans wrote:

It would be safer to write the new file to a temporary file, then swap the contents of the two files. There are MacOS File Manager functions that you can use to do this. I assume that the Windows API supports this sort of operation as well.

Though not quite as good as swapping the file contents, there's another method that's almost and good but more portable. Write out your new file to the same folder but with a temporary file name (just make up one that doesn't already exist). Then, when that's done successfully, rename the old file to a different temporary name, name your new file to its proper name, and delete the old file.

In any case, the idea is to put off deleting the old file as long as possible, so that if you crash (lose power, etc.) in the middle of saving, the user's data isn't lost.

Cheers,
- Joe

--
,------------------------------------------------------------------.
|    Joseph J. Strout           REAL Software, Inc.                |
|    joe at realsoftware dot com       http://www.realsoftware.com        |
`------------------------------------------------------------------'


<Prev in Thread] Current Thread [Next in Thread>