python 复制/移动文件

https://docs.python.org/3.6/library/shutil.html

shutil可以实现文件的复制,移动


 
 
  
  
  1. #复制文件:
  2. shutil.copyfile( "oldfile", "newfile") #oldfile和newfile都只能是文件
  3. shutil.copy( "oldfile", "newfile") #oldfile只能是文件夹,newfile可以是文件,也可以是目标目录
  4. #复制文件夹:
  5. shutil.copytree( "olddir", "newdir") #olddir和newdir都只能是目录,且newdir必须不存在
  6. #重命名文件(目录)
  7. os.rename( "oldname", "newname") #文件或目录都是使用这条命令
  8. #移动文件(目录)
  9. shutil.move( "oldpos", "newpos")
  10. shutil.move( "D:/知乎日报/latest/一张优惠券,换你的通讯录信息,你愿意吗?.pdf", "D:/知乎日报/past/")


转载链接:https://blog.csdn.net/u014170869/article/details/78885423

猜你喜欢

转载自blog.csdn.net/weixin_37830912/article/details/100103948