久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

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

用python批量移動文件

瀏覽:32日期: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 編程
相關文章:
主站蜘蛛池模板: 国产区福利 | 成人激情视频在线观看 | 成人精品国产一区二区4080 | 久久久精| 久久一区二区三区四区 | 久国产精品 | 亚洲欧美日韩国产 | 午夜成人在线视频 | 国产精品毛片一区视频播 | 羞羞的视频网站 | 在线观看国产日韩欧美 | 亚洲国产精品va在线看黑人 | 毛片免费看| 国产成人欧美一区二区三区的 | 成人免费毛片高清视频 | 激情视频在线观看 | 亚洲精品久久久久久一区二区 | 99国产精品一区 | 伊人www| 久久久国产精品入口麻豆 | 一区二区三区小视频 | 久久久免费精品 | 黄片毛片一级 | 一区二区在线免费观看 | 精品国产一区一区二区三亚瑟 | 国产精品免费一区二区三区四区 | 欧美精品二区中文乱码字幕高清 | 国产欧美精品一区二区三区 | 国产精品欧美一区二区三区不卡 | 九九久久久 | 日本欧美在线观看 | 亚洲国产精品网站 | 在线免费观看激情视频 | 国产精品久久久久久久久久99 | 一区日韩 | www.精品| 成年人网站在线免费观看 | 久久爱综合 | 国产伦精品一区二区三区在线 | 亚洲人成人一区二区在线观看 | 久久99精品久久久久子伦 |