I know that if I want to copy a file in Python, but not overwrite it, I can use this code:
if os.path.exists(dest): raise Exception("Destination file exists!") else: shutil.copy2(src, dest)
But the state of the world can change between the moment I call os.path.exists and the time I call copy2 . Is there a more preferred way of copying without overwriting, presumably where the copy operation will throw an exception if the destination already exists?
source share