Created
December 3, 2012 07:02
-
-
Save dengshilong/4193260 to your computer and use it in GitHub Desktop.
统计指定目录下的源文件行数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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