python shutil包 文件/目录的复制,移动

该模块拥有许多文件或文件的删除、移动、复制、重命名等功能。

import shutil

 #复制文件:

 shutil.copyfile("oldfile","newfile") #oldfile和newfile都只能是文件

 shutil.copy("oldfile","newfile") #oldfile只能是文件夹,newfile可以是文件,也可以是目标目录


 #复制文件夹:

 shutil.copytree("olddir","newdir") #olddir和newdir都只能是目录,且newdir必须不存在


 #移动文件(目录)

 shutil.move("oldpos","newpos")

 shutil.move("D:/知乎日报/latest/一张优惠券,换你的通讯录信息,你愿意吗?.pdf", "D:/知乎日报/past/")



 更多信息见:   参数详解 https://www.cnblogs.com/12345-/p/10345915.html

     

原文地址:https://www.cnblogs.com/luochunxi/p/12763418.html