-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlines.py
More file actions
31 lines (27 loc) · 1016 Bytes
/
lines.py
File metadata and controls
31 lines (27 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
# 15140
def count_lines_in_cpp_files(directory):
total_lines = 0
# Walk through the directory
for root, dirs, files in os.walk(directory):
# Exclude .git directory
if '.git' in dirs:
dirs.remove('.git')
for dir in dirs:
if "build" in dir:
dirs.remove(dir)
for file in files:
if file.endswith('.cpp'):
file_path = os.path.join(root, file)
print(f"file: {file_path}")
try:
with open(file_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
total_lines += len(lines)
except Exception as e:
print(f"Error reading file {file_path}: {e}")
return total_lines
# Example usage
project_directory = '/mnt/5EE9F38E0E9F2DC9/ispa-parser'
total_lines = count_lines_in_cpp_files(project_directory)
print(f"Total lines in all .cpp files: {total_lines}")