-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26c5239
commit c76f432
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from pathlib import Path | ||
import pandas as pd | ||
|
||
source_code_directory_path = Path("/home/kali/Desktop/urijs/src/") | ||
|
||
# 初始化计数器 | ||
total_words = 0 | ||
total_lines = 0 | ||
|
||
# 遍历目录中的每个文件 | ||
for file_path in source_code_directory_path.glob("*.js"): # 假设只统计JavaScript文件 | ||
if file_path.is_file(): # 确保是文件而不是目录 | ||
with open(file_path, 'r', encoding='utf-8') as file: | ||
lines = file.readlines() | ||
total_lines += len(lines) # 累加行数 | ||
total_words += sum(len(line.split()) for line in lines) # 累加单词数 | ||
|
||
# 准备数据 | ||
data = { | ||
"Number of Words in source code": [total_words], | ||
"Number of lines in source code": [total_lines] | ||
} | ||
|
||
# 创建DataFrame | ||
df = pd.DataFrame(data) | ||
|
||
# 保存到CSV文件 | ||
csv_file_path = "/home/kali/Desktop/source_code_statistics.csv" | ||
df.to_csv(csv_file_path, index=False) |