def main(): str = input('输入查询字符串: ') path_name = input('输入查询路径 (默认工作路径): ') if path_name == '': path_name = '.' minus = len(path_name) def list_file(str, path): list_all = os.listdir(path) for name_f in list_all: path_c = os.path.join(path, name_f) if os.path.isfile(path_c) and str in os.path.splitext(name_f)[0]: print(path_c[minus:]) # 把路径前缀去掉 elif os.path.isdir(path_c): list_file(str, path_c) if str in name_f: print(path_c[minus:]) list_file(str, path_name)if __name__ == '__main__': main()
Sign in to make a reply
Chris_Gardner_II