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