Safely renaming a file without overwriting

Diez B. Roggisch deets at nospam.web.de
Sat Oct 28 20:55:14 EDT 2006


Wolfgang Draxinger schrieb:
> Steven D'Aprano wrote:
> 
>> But the source file always exists, otherwise there is nothing
>> to rename! Do you mean, open the destination filename?
> 
> Of course I meant the destination file. Someone please spill some
> ice chilled water over me to get me awake again. Time to go to
> bed :-P before I make more dumb mistakes/typos...

But that doesn't help. Opening the destination file that way will only 
make a difference if _both_ processes that fight over that filename work 
that way. Which might be possible in the actual case, but not as a 
general recipe.

The link/unlink trick of Chetan sounds reasonable, though.



More information about the Python-list mailing list