How do you copy files from one location to another?

Andrew Berg bahamutzero8825 at gmail.com
Fri Jun 17 02:15:58 EDT 2011


On 2011.06.17 12:06 AM, John Salerno wrote:
> "On Windows, if dst already exists, OSError will be raised even if it
> is a file.."
If you try to create a file or directory that already exists on Windows,
you'll get a WindowsError with error code 183:
>>> os.mkdir('C:\\common\\games')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
WindowsError: [Error 183] Cannot create a file when that file already
exists: 'C:\\common\\games'

I'm pretty sure you have to delete the existing file before you can
"overwrite" it. You can try to write the file and delete the file and
try again in an except OSError block (this will catch WindowsError as
well since it's a subclass of OSError, and it will catch similar errors
on other platforms).



More information about the Python-list mailing list