loc.py 453 B

12345678910111213141516171819
  1. import os
  2. def get_loc(path):
  3. loc = 0
  4. with open(path, "rt", encoding='utf-8') as f:
  5. loc += len(f.readlines())
  6. return loc
  7. def get_loc_for_dir(path):
  8. loc = 0
  9. for root, dirs, files in os.walk(path):
  10. for file in files:
  11. if file.endswith('.h'):
  12. _i = get_loc(os.path.join(root, file))
  13. print(f"{file}: {_i}")
  14. loc += _i
  15. return loc
  16. print(get_loc_for_dir('src'))