In bash, if I have a directory foo
but no directory bar
, then the command
cp -r foo bar
will create the directory bar
and this directory will contain the contents of foo
.
The Python equivalent of this is shutil.copytree("foo", "bar")
.
However, if I have a directory foo
and also a directory bar
, then the command
cp -r foo bar
will create a new directory foo
underneath bar
with all the contents of foo
in it.
Is there a Python equivalent of this, without
a) invoking the actual command using
os.system
orb) manually extracting the base name of the directory
foo
, appending it to bar usingos.path.join
, and then runningcopytree
That is, does Python have a concept of copying into directories?
Update: Both of the "duplicate" questions have solutions that do not copy "into" directories but rather "over" directories. The use of such solutions would require manual extraction of the base name of directory foo
, appending it to bar
and then using distutils.dir_util.copy_tree
. I am explicitly looking for a solution that does not require this.
If bar
already exists, cp -r foo bar
will create a new foo
inside bar
with all contents of foo
. On the other hand distutils.dir_util.copy_tree
will put everything in foo
inside bar
without creating a new foo
.