[Tutor] Copy without overwrite?

Jeff Shannon jeff at ccvcorp.com
Tue Sep 21 23:46:23 CEST 2004

Kent Johnson wrote:

> Looking at copytree() I'm actually not sure what keeps it from working 
> if the directory already exists; the docs for os.mkdir() don't say it 
> will fail if the dir exists.

I'm not sure what the docs say, but...

[.... jeff]$ ls -ld example
drwxrwxr-x    2 jeff     jeff         4096 Sep 21 14:45 example
[.... jeff]$ python
Python 2.2.2 (#1, Feb 24 2003, 19:13:11)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import os
 >>> os.mkdir('example')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
OSError: [Errno 17] File exists: 'example'

Jeff Shannon
Credit International

More information about the Tutor mailing list