-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcalculate_lines.ps1
60 lines (52 loc) · 1.77 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
# 计算文件的行数
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
# .py 文件行数
$pyFiles = Get-ChildItem -Recurse -Filter "*.py"
foreach ($file in $pyFiles) {
$pyLineCount += Get-LineCount -filePath $file.FullName
}
# 计算 templates 目录及子目录下的 .html 文件行数
$templatesDir = "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 "ui 目录下的 .py 文件总行数: $pyLineCount"
Write-Host "ui/templates 目录下的 .html 文件总行数: $htmlLineCount"
Write-Host "当前目录下的 README.md 文件总行数: $readmeLineCount"
Write-Host "当前目录下的 .ps1 文件总行数: $ps1LineCount"
Write-Host "总行数: $totalLineCount"