Copy directory contents into a directory with python [duplicate] Copy directory contents into a directory with python [duplicate] python python

Copy directory contents into a directory with python [duplicate]


I found this code working which is part of the standard library:

from distutils.dir_util import copy_tree# copy subdirectory examplefromDirectory = "/a/b/c"toDirectory = "/x/y/z"copy_tree(fromDirectory, toDirectory)

Reference:


You can also use glob2 to recursively collect all paths (using ** subfolders wildcard) and then use shutil.copyfile, saving the paths

glob2 link: https://code.activestate.com/pypm/glob2/


from subprocess import calldef cp_dir(source, target):    call(['cp', '-a', source, target]) # Linuxcp_dir('/a/b/c/', '/x/y/z/')

It works for me. Basically, it executes shell command cp.