色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

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

用python批量移動文件

瀏覽:22日期: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 編程
相關文章:
主站蜘蛛池模板: 92精品国产自产在线观看 | 欧美性猛交xxxx免费看手交 | 九九爱精品 | 成年片免费网址网站 | 一级一级特黄女人精品毛片 | 理伦毛片| 91久久香蕉国产线看 | 成人国产在线看不卡 | 久草在线免费播放 | 日韩在线一区二区 | 成人免费网址在线 | 久久九九精品视频 | 天天黄色片 | 久久中文字幕综合不卡一二区 | 91网站网站网站在线 | 色综合色狠狠天天久久婷婷基地 | 免费观看成人久久网免费观看 | 手机毛片 | 免费a黄色| 国产激爽大片在线播放 | 国内精品免费一区二区观看 | 国产一区二区三区在线免费观看 | 黄色网址进入 | 日韩性网 | 97精品国产福利一区二区三区 | 中文字幕曰韩一区二区不卡 | 国产一区二区三区在线免费 | 久久久这里只有精品免费 | 国产在线精品香蕉综合网一区 | 国产一区二区免费播放 | 成年午夜一级毛片视频 | 国产精品久久久久久福利漫画 | 免费一级欧美片片线观看 | 久久女厕一次看个够 | 亚洲人成网站在线观看播放 | 国产精品免费看久久久香蕉 | 一区二区中文字幕亚洲精品 | 国产一区二区三区精品久久呦 | 真人一级毛片免费观看视频 | 午夜在线视频一区二区三区 | 亚洲精品久久久中文字 |