1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
import os, random, shutil
dir = r'G:/dataset/rgbdsm/rgdsm/256_256/three grades-class'
datename = ['20160607', '170707', '2018.05.14', '2018.05.23', '2018.05.29', '2018.06.08', '2018.06.12', '180625', '200528', '200603', '200612']
trainpath = dir + "\\train" for file in os.listdir(trainpath): filepath = os.path.join(trainpath,file) print("filepath = %s " % filepath)
files = os.listdir(filepath)
for date in datename: testpath = filepath + "\\" + date print("testpath = %s " % testpath) isExists = os.path.exists(testpath) if not isExists: os.makedirs(testpath) for file in files: if os.path.splitext(file)[1] == '.jpg': split=file[0:10] for date in datename: if date in split: shutil.move(os.path.join(filepath, file), os.path.join(filepath, date))
|