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

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

Python文件夾批處理操作代碼實(shí)例

瀏覽:103日期:2022-07-16 16:55:30

如圖所示,有一個(gè)test文件夾,里面有3個(gè)子文件夾,每個(gè)子文件夾中有若干圖片文件

Python文件夾批處理操作代碼實(shí)例

Python文件夾批處理操作代碼實(shí)例

#場(chǎng)景1 讀取一個(gè)文件夾中所有文件,存入到一個(gè)list表中

Python文件夾批處理操作代碼實(shí)例

#coding:utf-8from __future__ import absolute_importfrom __future__ import divisionfrom __future__ import print_functionimport numpy as npimport osimport sysimport mathimport numpyimport timeimport argparseimport randomimport cv2def findAllfile(path, allfile): filelist = os.listdir(path) for filename in filelist: filepath = os.path.join(path, filename) if os.path.isdir(filepath): #print(filepath) findAllfile(filepath, allfile) else: allfile.append(filepath) return allfile #場(chǎng)景1 讀取一個(gè)文件夾中所有文件,存入到一個(gè)list表中def process1(srcpath, imgprocess_result): #遍歷圖像文件夾 image_files = findAllfile(srcpath,[]) #image_files為所有文件的list #判斷 目錄是否存在,存在就刪除,并且重建 if os.path.exists(imgprocess_result): os.system('rm -rf ' + imgprocess_result) if not os.path.isdir(imgprocess_result): # Create the log directory if it doesn’t exist os.makedirs(imgprocess_result) #是否隨機(jī)打亂文件順序 #random.shuffle(image_files) #遍歷所有 for facepath in image_files: print('原始文件路徑:', facepath) #獲取文件名稱 data_split = facepath.strip().split('/') image_floder = data_split[-2] print('文件所在目錄:', image_floder) image_name = data_split[-1] print('文件名稱:', image_name) image_newfloder = imgprocess_result + '/' + image_floder #判斷 目錄是否存在,不存在就重建 if not os.path.isdir(image_newfloder): # Create the log directory if it doesn’t exist os.makedirs(image_newfloder) image_newpath = image_newfloder + '/' + image_name print('處理后的文件路徑:', image_newpath) #開始處理文件 #.............. # ##場(chǎng)景2 首先讀取一個(gè)文件夾中的所有子目錄,然后依次遍歷各個(gè)子目錄的所有文件def process2(srcpath, imgprocess_result): #找出所有的子目錄 filelist = os.listdir(srcpath) for filename in filelist: filepath = os.path.join(srcpath, filename) if os.path.isdir(filepath): print('原始子目錄路徑:', filepath) image_files = findAllfile(filepath,[]) for facepath in image_files:print('原始文件路徑:', facepath)#獲取文件名稱data_split = facepath.strip().split('/')image_floder = data_split[-2]print('文件所在目錄:', image_floder)image_name = data_split[-1]print('文件名稱:', image_name)image_newfloder = imgprocess_result + '/' + image_floder#判斷 目錄是否存在,不存在就重建if not os.path.isdir(image_newfloder): # Create the log directory if it doesn’t exist os.makedirs(image_newfloder)image_newpath = image_newfloder + '/' + image_nameprint('處理后的文件路徑:', image_newpath)#開始處理文件#..............##if __name__ == ’__main__’: #原始文件夾 srcpath = '/DATA/share/publicdata/face/dmt_face/test' #處理完畢后存放文件 imgprocess_result = '/DATA/share/publicdata/face/dmt_face/imgprocess_result' print('方法1nnnn') process1(srcpath, imgprocess_result) print('nnn方法2') process2(srcpath, imgprocess_result)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 亚洲成a人片在线观 | 日本天堂视频在线观看 | 成人不卡视频 | 久草在线视频免费播放 | 91成人在线免费视频 | 全部在线美女网站免费观看 | 美国做受三级的视频播放 | 亚洲综合久久久 | 亚洲精品成人7777在线观看 | 久久伊人免费视频 | 99视频久久精品久久 | 在线观看一二三区 | 国产成人亚洲综合 | 久久中精品中文 | 成年人网站在线 | 在线视频一区二区三区 | 国产在线视频自拍 | 免费观看女人一摸全是水 | 日本特黄a级高清免费酷网 日本特黄特色 | 国产又粗又黄又湿又大 | 美女国产在线观看免费观看 | 视频一区二区三区在线 | 一区二区三区在线看 | 亚洲成人综合网站 | 中文字幕在线观看91 | 成人在线播放 | 国产精品久久久久久久午夜片 | 伊人色综合久久天天网蜜月 | 手机看片日韩高清国产欧美 | 亚洲人成网国产最新在线 | 欧美精品一区二区精品久久 | 岛国毛片在线观看 | 日韩 欧美 中文 亚洲 高清 在线 | 亚洲第一页在线视频 | 97精品福利视频在线 | 亚洲国产成+人+综合 | 67id人成国产在线 | 日韩免费黄色片 | 久久国产三级 | 亚洲视频中文字幕在线观看 | 伊人婷婷色香五月综合缴激情 |