先上代码,之后再补充
import os import glob import shutil dir='....' if not os.path.exists(dir+'training'): os.mkdir(dir+'training') if not os.path.exists(dir+'testing'): os.mkdir(dir+'testing') for i in range(1,38): a='person{}'.format(i) file_name=dir+'training/'+a if not os.path.exists(file_name): os.mkdir(file_name) for i in range(38,41): a='person{}'.format(i) file_name=dir+'testing/'+a if not os.path.exists(file_name): os.mkdir(file_name) for j in range(1,10): s='s0{}*'.format(j) t='person{}'.format(j) s_file_name=dir+s t_file_name=dir+'training'+'/'+t+'/' for data in glob.glob(s_file_name): if not os.path.isdir(data): shutil.move(data,t_file_name) for j in range(10,38): s='s{}*'.format(j) t='person{}'.format(j) s_file_name=dir+s t_file_name=dir+'training'+'/'+t+'/' for data in glob.glob(s_file_name): if not os.path.isdir(data): shutil.move(data,t_file_name) for j in range(38,41): s='s{}*'.format(j) t='person{}'.format(j) s_file_name=dir+s t_file_name=dir+'testing'+'/'+t+'/' for data in glob.glob(s_file_name): if not os.path.isdir(data): shutil.move(data,t_file_name)