https://docs.python.org/3.6/library/shutil.html
shutil可以实现文件的复制,移动
-
#复制文件:
-
shutil.copyfile(
"oldfile",
"newfile")
#oldfile和newfile都只能是文件
-
shutil.copy(
"oldfile",
"newfile")
#oldfile只能是文件夹,newfile可以是文件,也可以是目标目录
-
-
#复制文件夹:
-
shutil.copytree(
"olddir",
"newdir")
#olddir和newdir都只能是目录,且newdir必须不存在
-
-
#重命名文件(目录)
-
os.rename(
"oldname",
"newname")
#文件或目录都是使用这条命令
-
-
#移动文件(目录)
-
shutil.move(
"oldpos",
"newpos")
-
shutil.move(
"D:/知乎日报/latest/一张优惠券,换你的通讯录信息,你愿意吗?.pdf",
"D:/知乎日报/past/")
转载链接:https://blog.csdn.net/u014170869/article/details/78885423