# -*- coding: utf-8 -*- # author:baoshan import os dirname = r'D: .shenma 1.聊城资料 1.数据资料 2.聊城年鉴数据2017年鉴' filename = ".xls" result = [] def search(dirname=dirname, filename=""): for item in os.listdir(dirname): item_path = os.path.join(dirname, item) if os.path.isdir(item_path): search(item_path, filename) elif os.path.isfile(item_path): if filename in item: global result result.append(item_path +";") print(item_path+";") if __name__ == '__main__': search(dirname, filename)
转自:https://www.cnblogs.com/hyacinthwyd/p/8997917.html
谢谢!