-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate_lines.ps1
73 lines (65 loc) · 2.31 KB
/
calculate_lines.ps1
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# 计算文件的行数
function Get-LineCount {
param (
[string]$filePath
)
try {
$lineCount = (Get-Content $filePath | Measure-Object -Line).Lines
return $lineCount
} catch {
Write-Warning "无法读取文件: $filePath"
return 0
}
}
# 初始化计数器
$totalLineCount = 0
$cAndHLineCount = 0
$pyLineCount = 0
$htmlLineCount = 0
$readmeLineCount = 0
$ps1LineCount = 0
# 计算 include 目录下的 .c 和 .h 文件行数
$includeDir = "include"
if (Test-Path $includeDir) {
$cAndHFiles = Get-ChildItem -Path $includeDir -Recurse -Filter "*.c"
$cAndHFiles += Get-ChildItem -Path $includeDir -Recurse -Filter "*.h"
foreach ($file in $cAndHFiles) {
$cAndHLineCount += Get-LineCount -filePath $file.FullName
}
}
# 计算 ui 目录及子目录下的 .py 文件行数
$uiDir = "ui"
if (Test-Path $uiDir) {
$pyFiles = Get-ChildItem -Path $uiDir -Recurse -Filter "*.py"
foreach ($file in $pyFiles) {
$pyLineCount += Get-LineCount -filePath $file.FullName
}
}
# 计算 ui/templates 目录及子目录下的 .html 文件行数
$templatesDir = "ui/templates"
if (Test-Path $templatesDir) {
$htmlFiles = Get-ChildItem -Path $templatesDir -Recurse -Filter "*.html"
foreach ($file in $htmlFiles) {
$htmlLineCount += Get-LineCount -filePath $file.FullName
}
}
# 计算当前目录下的 README.md 文件行数
$readmeFile = "README.md"
if (Test-Path $readmeFile) {
$readmeLineCount = Get-LineCount -filePath $readmeFile
}
# 计算当前目录下的 .ps1 文件行数
$ps1Files = Get-ChildItem -Path . -Filter "*.ps1" | Where-Object { $_.PSIsContainer -eq $false }
foreach ($file in $ps1Files) {
$ps1LineCount += Get-LineCount -filePath $file.FullName
}
# 计算总行数
$totalLineCount = $cAndHLineCount + $pyLineCount + $htmlLineCount + $readmeLineCount + $ps1LineCount
# 输出结果
Write-Host "======== 文件行数统计 ========"
Write-Host "include 目录下的 .c 和 .h 文件总行数: $cAndHLineCount"
Write-Host "ui 目录下的 .py 文件总行数: $pyLineCount"
Write-Host "ui/templates 目录下的 .html 文件总行数: $htmlLineCount"
Write-Host "当前目录下的 README.md 文件总行数: $readmeLineCount"
Write-Host "当前目录下的 .ps1 文件总行数: $ps1LineCount"
Write-Host "总行数: $totalLineCount"