1 import os 2 3 def file_name(file_dir): 4 L=[] 5 for root, dirs, files in os.walk(file_dir): 6 for file in files: 7 if os.path.splitext(file)[1] == ‘.xlsx‘: 8 # L.append(os.path.join(root, file)) 9 # file_name = file[0:-4] #去掉.xlsx 10 file_name = file 11 if ‘员工信息表‘ in file_name: 12 L.append(file_name) 13 return L 14 15 16 print(file_name(r‘D:‘))