Safely renaming a file without overwriting
Steven D'Aprano
steve at REMOVE.THIS.cybersource.com.au
Sat Oct 28 18:40:49 EDT 2006
On Sun, 29 Oct 2006 00:29:06 +0200, Wolfgang Draxinger wrote:
> Steven D'Aprano wrote:
>
>> Open "the" file? There are potentially two files -- the source
>> and destination. I only want to do the rename if the
>> destination *doesn't* exist, so there is no destination file to
>> open. How will it help me to lock the source file? Have I
>> misunderstood?
>
> I forgot to say, to open the source file with O_CREAT | O_EXCL.
> The open will fail if the file already exists.
But the source file always exists, otherwise there is nothing to rename!
Do you mean, open the destination filename?
--
Steven.
More information about the Python-list
mailing list