This question already has an answer here:
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"
.
It works for me. Basically, it executes shell command cp.
The python libs are obsolete with this function. I've done one that works correctly:
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/
I found this code working.