亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

用python批量移動文件

瀏覽:28日期: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批量移動文件的詳細(xì)內(nèi)容,更多關(guān)于python批量移動文件的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 欧美喷水 | 中文字幕日韩专区 | 亚洲黄色片一级 | 欧美一级毛片在线看视频 | 中文在线免费不卡视频 | 视频在线观看大片 | 久久精品国产亚洲麻豆 | 亚洲欧美日韩国产精品第不页 | 亚洲第一a亚洲 | 国产五月色婷婷六月丁香视频 | 看全色黄大色黄女片爽老外 | 国产美女91呻吟求 | 欧美一级毛片免费大片 | 2019理论国产一级中字 | 激情五月色综合婷婷大片 | 欧美亚洲一区二区三区在线 | 成人午夜大片免费视频77777 | 在线国产一区二区三区 | 国产欧美日韩中文字幕 | 三级黄色毛片网站 | 国产女人伦码一区二区三区不卡 | 国产娱乐凹凸视觉盛宴在线视频 | 国产精品国产三级国产an不卡 | 色色视频在线观看 | 亚洲女初尝黑人巨高清在线观看 | 久久精品国产亚洲香蕉 | 国产在线观看黄色 | 特级毛片aaaa级毛片免费 | 亚洲你xx我xx网站 | 老司机成人精品视频lsj | 啪视频在线观看 | 免费三级毛片 | 国产精品国产亚洲精品不卡 | 玖玖爱视频在线观看 | 九色亚洲 | 久久精品黄色 | 国产精品免费视频播放器 | 国产在线观看精品 | 极品国产高颜值露脸在线 | 性激烈的欧美三级高清视频 | 在线观看免费黄色片 |