#复制文件:
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(".pdf", "D:/xxx/")
import shutil 进行复制和移动文件或者文件夹
最新推荐文章于 2025-07-19 07:17:30 发布