国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

用python批量移動文件

瀏覽:33日期:2022-06-29 18:31:18

我是用來移動圖片的,其他格式的文檔也是可以的,改下后綴列表就可以了

import os,shutilimport datetime #將文件夾里的圖片全部移動到新文件夾中#revised by Stephen Shen 2020-3-10 09:28:50 def renameFile(dstpath): fdirname,fbasename=os.path.split(dstpath) #文件名相同但大小不同 fname,fext=os.path.splitext(fbasename) nowtime=datetime.datetime.now() strtime=str(nowtime.year)+str(nowtime.month)+str(nowtime.day)+str(nowtime.hour)+str(nowtime.minute) newfbasename=fname+’-’+strtime+fext dstpath=os.path.join(fdirname,newfbasename) return dstpath def moveFile(oldpath,newpath): if os.path.exists(newpath):newpath=renameFile(newpath) try:shutil.move(oldpath,newpath)print(oldpath+’ is moved’) except:print(oldpath+’ is skipped’) inpath=r’K:fileExtractedimagesFromDocs’ outpath=r’K:filesExtracted’image_ext=[’.JPG’,’.jpg’,’.png’,’.PNG’,’.jpeg’,’.wdp’]image_outpath=os.path.join(outpath,’image’)doc_ext=[’.doc’,’.docx’]doc_outpath=os.path.join(outpath,’doc’) emf_ext=[’.emf’]emf_outpath=os.path.join(image_outpath,’emf’)wmf_ext=[’.wmf’]wmf_outpath=os.path.join(image_outpath,’wmf’) if not os.path.exists(outpath): os.makedirs(outpath)if not os.path.exists(image_outpath): os.makedirs(image_outpath)if not os.path.exists(doc_outpath): os.makedirs(doc_outpath)if not os.path.exists(emf_outpath): os.makedirs(emf_outpath)if not os.path.exists(wmf_outpath): os.makedirs(wmf_outpath) for folder,subfolders,files in os.walk(inpath): for file in files:oldpath=os.path.join(folder,file) if os.path.splitext(file)[-1] in image_ext: newpath=os.path.join(image_outpath,file) moveFile(oldpath,newpath)elif os.path.splitext(file)[-1] in doc_ext: newpath=os.path.join(doc_outpath,file) moveFile(oldpath,newpath)elif os.path.splitext(file)[-1] in emf_ext: newpath=os.path.join(emf_outpath,file) moveFile(oldpath,newpath)elif os.path.splitext(file)[-1] in wmf_ext: newpath=os.path.join(wmf_outpath,file) moveFile(oldpath,newpath)else: continueprint(’done’)

然后再刪除空文件夾

import os,shutil #將文件夾里的空文件夾刪除#revised by Stephen Shen 2020-3-8 17:50:24 inpath=r’E:pics-moving待分類照片’ for folder,subfolders,files in os.walk(inpath): if not os.listdir(folder):shutil.rmtree(folder)# print(folder+’ is empyt’)print(folder+’ is deleted’) print(’done’)

以上就是用python批量移動文件的詳細內容,更多關于python批量移動文件的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 视频三区精品中文字幕 | 欧美午夜精品久久久久免费视 | 世界一级毛片 | 毛片网站在线看 | 亚洲成av人片在线观看无码 | 欧美一区二区三区免费 | 黄色三级视频网站 | 国产欧美va欧美va香蕉在线 | 成人免费毛片一区二区三区 | 成年女人毛片免费播放人 | 国产高清一区二区三区四区 | 在线视频中文字幕 | 久久亚洲国产午夜精品理论片 | 亚洲欧美网站 | 国内视频一区 | 国产真实孩交 | 亚洲欧美午夜 | 久久久精品久久久久三级 | 精品91精品91精品国产片 | 992人人tv香蕉国产精品 | 国产精品久久久久毛片真精品 | 99精品视频一区在线观看miya | 欧美精品黄页免费高清在线 | 欧美一区亚洲二区 | 国产精品理论片在线观看 | 日本免费二区三区久久 | 免费观看成人毛片 | 国产激爽大片在线播放 | 一级毛片日韩a欧美 | 美女被免费网站在线视频软件 | 一级黄色美女视频 | 国产男女视频在线观看 | 欧美一级毛片高清视频 | 99精品福利 | 天天都色| 国产香蕉98碰碰久久人人 | 免费看a级毛片 | 免费a网| 高清在线一区二区 | 国产欧美视频综合二区 | 成人影院欧美大片免费看 |