realbasic-nug
[Top] [All Lists]

Re: Safe File Saving

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Safe File Saving
From: Norman Palardy <npalardy at great-white-software dot com>
Date: Tue, 31 Jan 2006 18:14:37 -0800
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <0ED3E4E6-61C7-486A-9B53-E6E1F109CED8 at athenet dot net> <ba449adfed82d9dfc68b68d529198470 at great-white-software dot com> <A785996A-1311-48DA-9212-07755B545DA9 at athenet dot net>

On Jan 31, 2006, at 5:52 PM, Adam Ernst wrote:

On Jan 31, 2006, at 7:49 PM, Norman Palardy wrote:

     if oldFile.Exists then f.CreationDate = oldFile.CreationDate
// oldFile probably exists. But I don't want to delete it first--that would sacrifice safety.
if oldfile.exists then oldFile.delete
     f.MoveFileTo oldFile
if f.LastErrorCode <> 0 then return false // LastErrorCode=183, "file already exists"

That deletes the oldFile. What if the move then fails (permissions error, or something)?
You might try renaming the old file, but that may fail for privilege reasons as well.

Move is just a MOVE, not a MOVE AND REPLACE

On Mac, it's a move and replace (I think).
It can be.
The Mac, because of the Unix underpinnings will let you replace a file that is open (including an executable).
In fact try deleting a file you are writing to.
The finder may not let you, but in Terminal if you do "rm" on a file being written to it will delete BUT the unix system hangs on to it until you free it up (and this can be a nasty source of disappearing disk space :))

Some versions of Windows will. Some will not

However, if oldFile is "busy" you may not be able to remove it, rename it or anything else

Yes. That's fine. I just want to replace it if it's not busy.
Then you get an error if it is.

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>


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