-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount_lines_of_code.py
28 lines (22 loc) · 1.01 KB
/
count_lines_of_code.py
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
# https://chat.openai.com/c/667c0bea-3f6b-4ed7-a2e0-1bdd5ad6db9e
import os
# Set this to your directory path
directory_path = 'C:\\Users\\mdrou\\OneDrive\\TPS\\3A\\Bioinformatique\\Projet-Code\\src'
# Function to count non-empty lines in a file
def count_non_empty_lines(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
return sum(1 for line in file if line.strip())
# Counters for test and non-test files
test_lines = 0
non_test_lines = 0
# Process each file in the directory
for filename in os.listdir(directory_path):
if filename.endswith('.py'): # Check if it's a Python file
file_path = os.path.join(directory_path, filename)
if filename.startswith('test_'): # Check if it's a test file
test_lines += count_non_empty_lines(file_path)
else:
non_test_lines += count_non_empty_lines(file_path)
# Print the results
print(f"Total non-empty lines in test files: {test_lines}")
print(f"Total non-empty lines in non-test files: {non_test_lines}")