import os, sys from stat import * from typing import Callable def visit_file(file): print('visiting', file) def walktree(top, callback: Callable): print(f'{top=}') for f in os.listdir(top): path = os.path.join(top, f) st_mode = os.stat(path, follow_symlinks=False).st_mode if S_ISDIR(st_mode): walktree(path, callback) elif S_ISREG(st_mode): callback(path) else: print('skipping %s' % path) walktree('log_', visit_file)
标签:Python,top,recurse,st,mode,file,directory,path,os From: https://www.cnblogs.com/dissipate/p/16876606.html