[研究]PowerShell 計算目錄中所有檔案的總行數
2024-10-01
環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 19
********************************************************************************
L2.ps1
# 設定要檢查的目錄路徑
$directoryPath = "C:\Path\To\Your\Directory"
# 總行數計數器
$totalLines = 0
# 獲取所有檔案,遞迴搜尋子目錄
Get-ChildItem -Path $directoryPath -Recurse -File | ForEach-Object {
# 讀取每個檔案的內容並計算行數
$lineCount = (Get-Content $_.FullName).Count
$totalLines += $lineCount
}
# 輸出總行數,立即顯示
Write-Host "Total lines in files: $totalLines"
|
執行結果
註:可以用 CLOC(Count Lines of Code)軟體計算。
(完)

沒有留言:
張貼留言