亚洲免费在线视频-亚洲啊v-久久免费精品视频-国产精品va-看片地址-成人在线视频网

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

用python批量移動(dòng)文件

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

我是用來(lái)移動(dòng)圖片的,其他格式的文檔也是可以的,改下后綴列表就可以了

import os,shutilimport datetime #將文件夾里的圖片全部移動(dòng)到新文件夾中#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批量移動(dòng)文件的詳細(xì)內(nèi)容,更多關(guān)于python批量移動(dòng)文件的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 日韩欧美色综合 | 一级高清毛片免费a级高清毛片 | 香蕉超级碰碰碰97视频蜜芽 | 国产一级在线观看视频 | 欧美三级做爰全过程 | a一级爱做片免费 | 韩国精品欧美一区二区三区 | 成人午夜久久 | 大尺度福利视频奶水在线 | 免费高清毛片在线播放视频 | 久久亚洲精品视频 | 亚洲精品一区二区三区网址 | 亚洲人成网7777777国产 | 综合成人在线 | 一级毛片不卡片免费观看 | 欧美一级爱操视频 | 欧美亚洲国产日韩一区二区三区 | 欧美一区二区三区高清视频 | 精品一区二区三区免费爱 | 白嫩美女一级毛片免费看 | 日韩欧美在线视频观看 | 国产成人免费观看在线视频 | 国产三级香港三韩国三级 | 国产一区二区三区免费大片天美 | 在线视频 国产交换 | 午夜久久视频 | a级毛片在线观看 | 一级做a爰片久久毛片唾 | 综合爱爱网 | 日本美女一区二区三区 | 亚洲综合图片人成综合网 | 久久九九精品视频 | 日本伊人精品一区二区三区 | 欧美一级日韩一级亚洲一级 | 久久久久久久免费视频 | 国产国产人免费视频成69堂 | 99在线热视频 | 亚洲精品专区一区二区三区 | 欧美在线bdsm调教一区 | 伊在人亚洲香蕉精品区 | 99久久精品久久久久久清纯 |