Copying Directories with shutil.copytree
作者:XD / 发表: 2024年7月29日 22:07 / 更新: 2024年7月29日 22:07 / 编程笔记 / 阅读量:777
In Python, shutil.copytree
is a simple and efficient way to copy entire directories, including all their files and subdirectories.
Basic Usage
To use shutil.copytree
, you just need to specify the source directory and the destination directory:
import shutil
# Copy the source directory to the destination
shutil.copytree('path/to/source', 'path/to/destination')
This command will copy all contents from path/to/source
to path/to/destination
. If the destination directory does not exist, it will be created automatically. This function is ideal for duplicating directory structures and their contents in one simple step.
相关标签