Copy file or directories recursively in Python

前端 未结 5 896
无人及你
无人及你 2020-11-27 12:17

Python seems to have functions for copying files (e.g. shutil.copy) and functions for copying directories (e.g. shutil.copytree) but I haven\'t fou

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 12:27

    shutil.copy and shutil.copy2 are copying files.

    shutil.copytree copies a folder with all the files and all subfolders. shutil.copytree is using shutil.copy2 to copy the files.

    So the analog to cp -r you are saying is the shutil.copytree because cp -r targets and copies a folder and its files/subfolders like shutil.copytree. Without the -r cp copies files like shutil.copy and shutil.copy2 do.

提交回复
热议问题