统计文本文件记录

$folderPath = Read-Host "Enter the folder path"
function mainMenu {
while($prompt -ne ''){

$totaLines = 0
$n = 0
Get-ChildItem -Path $folderPath -Filter *.txt -Recurse  | ForEach-Object {
$fileLines = (Get-Content $_.FullName | Measure-Object -Line).Lines
Write-Host "$($_.Name): $fileLines lines"  -ForegroundColor "Yellow" 
$n+=1
$totaLines+=$fileLines
}

write-Host

$prompt = Read-Host "Should the first row be excluded as  the header row: Y or N (Leave blank quit )"
if ($prompt -eq "Y"){
$totaLines=$totaLines - $n
Write-Host "Total lines :$totaLines lines" -ForegroundColor "Green"
}
if ($prompt -eq "N"){
Write-Host "Total lines :$totaLines lines"  -ForegroundColor "Green"
}
}
}
mainMenu

  

posted @ 2025-12-09 22:57  tec2019  阅读(4)  评论(0)    收藏  举报