Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dengshilong
Created December 3, 2012 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dengshilong/4193260 to your computer and use it in GitHub Desktop.
Save dengshilong/4193260 to your computer and use it in GitHub Desktop.
统计指定目录下的源文件行数
# -*- coding: utf-8 -*-
"""统计指定目录下,指定源文件类型的总行数"""
from collections import defaultdict
import os
d = defaultdict(int)
path = r"D:/vc++workspaces" #路径
f = ['.c','.cpp'] #需要统计源文件的类型
for dirpath,dirnames,filenames in os.walk(path):
for filename in filenames:
path = os.path.join(dirpath, filename)
ext = os.path.splitext(filename)[1]
if ext in f:
try:
d[ext] += len(list(open(path)))
except:
pass
for ext in f:
print (ext,d[ext])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment