The copytree method of shutil module

The copytree method of the shutil module copies a folder with all the files and folders that are in it. In the first parameter of the method, we specify the source path to the folder. In the second parameter, we specify the destination path. If the deletion is successful, the method returns the name of the new path of the copied folder.

Syntax

pythonimport shutil

shutil.copytree(where do we copy from, where do we copy to)

Example

Let's recursively copy the folder dir:

pythonimport shutil

print(shutil.copytree('dir', 'dir1'))

The result of the executed code:

pythondir1

See also

  • method move of module shutil,
    which recursively moves a file or directory
  • method rmtree of module shutil,
    which recursively deletes a folder
  • method makedirs of module os,
    which creates folders
  • method copy of module shutil,
    which copies a file while preserving the access mode
  • method copy2 of module shutil,
    which copies a file with metadata
  • method remove of module os,
    which deletes the file