You can use the shutil
module to copy a directory in Python. The shutil
module provides functions for file operations, and one of the functions is copytree()
, which recursively copies an entire directory tree from one location to another.
Here's an example of how to use the copytree()
function:
main.py251 chars12 lines
In this example, we first specify the source directory and the destination directory. We then use the copytree()
function to copy the source directory recursively to the destination directory. Note that the destination directory must not already exist, otherwise the function will raise an error. If you need to overwrite the destination directory, you can use the rmtree()
function from the os
module to delete the destination directory before calling copytree()
.
gistlibby LogSnag