代码如下:
import os,shutil total = 0 def HandleDir(root, dir): pass def DoFilter(file): focus = [".lua"] ext = os.path.splitext(file)[-1] if ext in focus: return True return False def HandleFile(root, file): global total if not DoFilter(file): return full_path = os.path.join(root, file) lines = open(full_path).readlines() total = total + len(lines) print os.path.join(root, file) print len(lines) def WalkThroughPath(dst_path): try: for root, dirs, files in os.walk(dst_path): for dir in dirs: HandleDir(root, dir) for file in files: HandleFile(root, file) print total except WindowsError: pass def main(): WalkThroughPath("D:\Tmp\jishi_win7_lr") if __name__ == "__main__": main()