copytree if directory exists

T

Thomas Guettler

Hi,

I need to copy a directory into an existing directory.
shutil.copytree does complain that the directory already
exists.

I need something like "cp -rp": Copy recursively, overwrite
if file already exist. Preserve mtime and modes if possible.

A keyword argument "may_exist=1" for shutil.copytree would be nice.

Thomas
 
P

Peter Hansen

Thomas said:
I need to copy a directory into an existing directory.
shutil.copytree does complain that the directory already
exists.

I need something like "cp -rp": Copy recursively, overwrite
if file already exist. Preserve mtime and modes if possible.

A keyword argument "may_exist=1" for shutil.copytree would be nice.

Thomas, shutil.copytree is written in pure Python. Grab the
source and stick in the appropriate exception handling around
the call to os.mkdir() and you should have about what you
need...

-Peter
 
T

Thomas Heller

Peter Hansen said:
Thomas, shutil.copytree is written in pure Python. Grab the
source and stick in the appropriate exception handling around
the call to os.mkdir() and you should have about what you
need...

Also, distutils.dir_util has a fairly flexible copy_tree function.

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,212
Messages
2,571,101
Members
47,695
Latest member
KayleneBee

Latest Threads

Top