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: Charles Yeomans <yeomans at desuetude dot com>
Date: Fri, 30 Aug 2002 15:04:19 -0400

On Friday, August 30, 2002, at 02:53  PM, Joseph J. Strout wrote:

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.


Sure, but it's much more macho to use a toolbox call.

Charles Yeomans




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