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 17:49:58 -0800
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <0ED3E4E6-61C7-486A-9B53-E6E1F109CED8 at athenet dot net>

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

I'm trying to save a file the 'safe' way, by creating a temporary file, saving the data to there, and then moving that temporary file on top of the existing file. But on Windows, I get error 183, "file already exists". Here's my code:

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

Any suggestions? What's the "proper" way to do this?

Thanks,

Adam Ernst

     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"

Move is just a MOVE, not a MOVE AND REPLACE
However, if oldFile is "busy" you may not be able to remove it, rename it or anything else

_______________________________________________
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>