-5

How can I copy all contents (including folders) from folder A to the existing folder B with Python?

  • 1
    What have you tried? How did it fail? –  Nov 27 '20 at 16:23
  • 1
    Hello and welcome to SO. On this website, we encourage you to post your efforts and tell what problem you encountered. For this kind of question, please use google first. – Daemon Painter Nov 27 '20 at 16:24
  • This may be a duplicate: [How do I copy an entire directory of files into an existing directory using Python?](https://stackoverflow.com/questions/1868714/how-do-i-copy-an-entire-directory-of-files-into-an-existing-directory-using-pyth) – CryptoFool Nov 27 '20 at 16:35

1 Answers1

0

You can use the copytree function from the shutil package https://docs.python.org/3/library/shutil.html#shutil.copytree.

from shutil import copytree

src_path = "path/of/your/source/dir"
dest_path = "path/of/your/destination/dir"

copytree(src_path, dest_path, dirs_exist_ok=True)

The dirs_exist_ok=True parameter is useful if the dest_path already exists, and you want to overwrite the existing files.

Cristian
  • 119
  • 3
  • I don't think this is quite what the OP asked for. I think they want to copy the Contents Of `path/of/your/source/dir` rather than copying the directory itself. – CryptoFool Nov 27 '20 at 16:44