I have the folder /a/b/c/d/ and I want to copy d/ into destination /dst/.
However, shutil.copytree("/a/b/c/d", "/dst") produces /dst/a/b/c/d.
I only want /dst, or even /dst/d would suffice, but I don't want all the intermediate folders.
[edit]
As others have noted, copytree does what I want - I had unintentionally added the full path of the source to my destination!
Given this file structure (on my directory
/tmp):If you do
shutil.copytree("/tmp/a", "/tmp/dst")you will get:But if you do
shutil.copytree('/tmp/a/b/c/d', '/tmp/dst/d')you get:And
shutil.copytree('/tmp/a/b/c/d', '/tmp/dst'):shutil.copytreealso takes relative paths. You can do:Or, since Python 3.6, you can use pathlib arguments to do:
Either case, you get the same result as
shutil.copytree('/tmp/a/b/c/d', '/tmp/dst')