import osdirPath = '.'def problem2(path, key=None): try: for x in os.listdir(path): # 列出所有文件或文件夹 if os.path.isdir(x): # 是目录 problem2(os.path.join(path, x), key) else: # 是文件 if key: # 有关键字 if key in x: # 打印出含关键字的路径 print(os.path.join(path, x)) else: # 无关键字,则全部显示 print(os.path.join(path, x)) except Exception as e: raise eproblem2(dirPath, '.py')
Sign in to make a reply
Silvers丶Rayleigh