import os
path = "F:\poject\sv"
list_file_type = ['v', 'sv', 'svh', 'c', 'cpp']
def get_count(fh):
ret = 0
flag = 0
list_line = fh.readlines()
for line in list_line:
line = line.strip()
if len(line) == 0:
continue
if line[0:2] == '//':
continue
if flag == 1:
if '*/' in line:
flag = 0
continue
if line[0:2] == '/*':
flag = 1
if '*/' in line:
flag = 0
continue
ret += 1
return ret
def start():
total = 0
for root, dirs, files in os.walk(path):
for file in files:
type = file.split('.')[-1]
if not type in list_file_type:
continue
file_path = os.path.join(root, file)
fh = open(file_path, "r")
ret = get_count(fh)
total += ret
print(str(ret).ljust(5) + file_path)
print("lines of code: " + str(total))
if '__main__' == __name__:
start()
SV代码行数统计脚本(python)
最新推荐文章于 2024-06-14 05:47:29 发布