-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
46 lines (36 loc) · 1.51 KB
/
Copy pathmain.py
File metadata and controls
46 lines (36 loc) · 1.51 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# import os
# PATH = "C:/dev/DSA/Dsa"
# files = 0
# lineofcode = 0
# dirs = set()
# for dirpath, _, filenames in os.walk(PATH):
# # Track every directory visited
# dirs.add(dirpath)
# for file in filenames:
# if file.endswith('.py'):
# files += 1
# file_path = os.path.join(dirpath, file)
# # Read file and count non-blank, non-comment lines
# with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
# lineofcode += sum(1 for line in f if line.strip() and not line.strip().startswith('#'))
# print(f"Total Python files: {files}")
# print(f"Total lines of code (excluding comments/blanks): {lineofcode}")
# print(f"Total folders: {len(dirs)}")
import os
PATH = "C:/dev/DSA/Dsa"
files = 0
lineofcode = 0
dirs = set()
for dirpath, dirnames, filenames in os.walk(PATH):
# Ignore hidden, cache, and virtual environment folders
dirnames[:] = [d for d in dirnames if not d.startswith('.') and d != '__pycache__' and d != 'venv']
dirs.add(dirpath)
for file in filenames:
if file.endswith('.py'):
files += 1
file_path = os.path.join(dirpath, file)
with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
lineofcode += sum(1 for line in f if line.strip() and not line.strip().startswith('#'))
print(f"Total Python files: {files}")
print(f"Total lines of code (excluding comments/blanks): {lineofcode}")
print(f"Total folders: {len(dirs)}")