可以写一个 python 脚本来用
[Python] 纯文本查看 复制代码 import os
def count_lines_in_file(file_path):
try:
with open(file_path, 'r', encoding='utf-8') as file:
lines = file.readlines()
return len(lines)
except Exception as e:
print(f"Error reading {file_path}: {str(e)}")
return 0
def count_c_code_lines_in_directory(directory_path):
total_lines = 0
for root, _, files in os.walk(directory_path):
for file in files:
if file.endswith(".c") or file.endswith(".h"):
file_path = os.path.join(root, file)
lines_count = count_lines_in_file(file_path)
total_lines += lines_count
return total_lines
if __name__ == "__main__":
folder_path = input("请输入要查找的文件夹路径: ")
total_lines = count_c_code_lines_in_directory(folder_path)
print(f"文件夹中的C代码总行数: {total_lines}")
|