glob.glob 匹配文件

时间:2023-03-09 21:20:31
glob.glob 匹配文件

glob.glob以列表形式返回匹配的文件路径

只有一个参数:文件的匹配规则

e.g.

>>>res_home = '/vip_data_center/test_envs/trainer/resource'
>>>model_name = 'caffe_models'
>>>nn_name = 'lenet'
>>>res_dir = os.path.join(res_home, model_name, nn_name)
>>>quantize_path = glob.glob(os.path.join(res_dir, '*.quantize'))
>>>quantize_path
['/vip_data_center/test_envs/trainer/resource/caffe_models/lenet/lenet_a.quantize']
>>>quantize_path = glob.glob(os.path.join(res_dir, '*.quantize'))[-1]
>>>quantize_path
'vip_data_center/test_envs/trainer/resource/caffe_models/lenet/lenet_a.quantize'