av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

用python批量移動文件

瀏覽:39日期: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久久久 | 日韩福利一区 | 在线成人| 欧美国产在线视频 | 成人扒开伸进免费观看 | 一区二区三区网站 | 国产日韩一区二区三区 | 麻豆三级视频 | 国产精品看片 | 999精品在线 | 日本中文字幕一区 | 婷婷97| 在线视频h | 欧美日韩国产激情 | 一级片在线免费观看 | 中文字幕在线免费观看 | 天天操夜夜操 | 欧美国产日韩一区二区 | 三级黄色片免费看 | 一区二区三区四区在线播放 | 日韩欧美精品在线观看 | 欧美成人精品欧美一级私黄 | 国产精品久久久久久久 | 国产免费91 | 香蕉视频在线观看网站 | a毛片视频 | 22精品一区二区三区 | 张津瑜国内精品www在线 | 五月婷婷丁香花 | 操操操干干干 | 免费av片 | 欧美视频一区二区三区 | 亚洲黄色网址 | 99这里只有精品视频 | 一区二区三区在线观看视频 | 成人涩涩| 亚洲在线播放 | 亚洲国产成人精品女人久久久 | 国产激情一区二区三区 | av色在线 | 另类小说第一草 |