Python 移动文件夹所有的文件到另外一个文件夹,重复的跳过
生活随笔
收集整理的這篇文章主要介紹了
Python 移动文件夹所有的文件到另外一个文件夹,重复的跳过
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import os,shutildef move_file(orgin_path,moved_path):dir_files=os.listdir(orgin_path) #得到該文件夾下所有的文件for file in dir_files:file_path=os.path.join(orgin_path,file) #路徑拼接成絕對路徑if os.path.isfile(file_path): #如果是文件,就打印這個文件路徑if file.endswith(".txt"):if os.path.exists(os.path.join(moved_path,file)):print("有重復文件!!,跳過,不移動!!!")continueelse:shutil.move(file_path, moved_path)if os.path.isdir(file_path): #如果目錄,就遞歸子目錄move_file(file_path,moved_path)print("移動文件成功!")if __name__ == '__main__':orgin_path = r'C:\Users\Administrator\Desktop\AiShu\AiShuWork\from' # 這個是你數據源 文件夾moved_path = r'C:\Users\Administrator\Desktop\AiShu\AiShuWork\from_to' # 這個是你想要移動到哪里的的文件夾move_file(orgin_path,moved_path)
總結
以上是生活随笔為你收集整理的Python 移动文件夹所有的文件到另外一个文件夹,重复的跳过的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python中的requests模块的使
- 下一篇: python selenium 鼠标移动