Python—批量複製檔案
阿新 • • 發佈:2018-12-13
批量複製檔案,並修改後綴名
import os,shutil #yml檔案根路徑 ymlroot = 'E:\\GTEA_gaze\\' # 原始圖片根路徑 srcroot='E:\\GTEA_Gaze_Dataset\\png\\' # 目標圖片根路徑 dstroot='E:\\Gaze\\' for i in range(22): j = "%03d" % i ymlpath = ymlroot + str(j) #依次去提取001,002,...資料夾下的檔案 srcpath = srcroot + str(j) dstpath = dstroot + str(j) L = file_name(ymlpath) #批量提取檔案的函式 for k in L: # 找對應的圖片 src=os.path.join(os.path.abspath(srcpath),k+'.png') # 重新命名,改為jpg格式 dst=os.path.join(os.path.abspath(dstpath),k+'.jpg') # 執行操作,複製檔案 shutil.copyfile(src,dst)
file_name函式地址:https://blog.csdn.net/u014421797/article/details/83243042