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
import shutil
shutil.copytree(where do we copy from, where do we copy to)
Example
Let's recursively copy the folder dir:
import shutil
print(shutil.copytree('dir', 'dir1'))
The result of the executed code:
dir1
See also
-
method
moveof moduleshutil,
which recursively moves a file or directory -
method
rmtreeof moduleshutil,
which recursively deletes a folder -
method
makedirsof moduleos,
which creates folders -
method
copyof moduleshutil,
which copies a file while preserving the access mode -
method
copy2of moduleshutil,
which copies a file with metadata -
method
removeof moduleos,
which deletes the file