prosseek prosseek - 1 year ago 95
Python Question

Copy directory contents into a directory with python

I have a directory /a/b/c that has files and subdirectories.
I need to copy the /a/b/c/* in the /x/y/z directory. What python methods can I use?

I tried shutil.copytree("a/b/c", "/x/y/z"), but python tries to create /x/y/z and raises an error "Directory exists".

Answer Source

I found this code working.

from distutils.dir_util import copy_tree

# copy subdirectory example
fromDirectory = "/a/b/c"
toDirectory = "/x/y/z"

copy_tree(fromDirectory, toDirectory)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download