Files
dx4/dengi.ps1
T
2026-01-07 22:27:52 +03:00

24 lines
712 B
PowerShell

# save as Count-Word.ps1
param(
[string]$Root = ".",
[string]$Word = "dengi"
)
$pattern = "\b" + [regex]::Escape($Word) + "\b"
$count = 0
Get-ChildItem -Path $Root -Recurse -File -ErrorAction SilentlyContinue |
Where-Object { $_.FullName -notmatch "\\dist(\\|$)" } |
ForEach-Object {
try {
# ïðî÷èòàòü òåêñòîâûé ôàéë; åñëè íå òåêñòîâûé — ïðîïóñòèòü
$text = Get-Content -LiteralPath $_.FullName -ErrorAction Stop -Raw -Encoding UTF8
} catch {
try { $text = Get-Content -LiteralPath $_.FullName -ErrorAction Stop -Raw -Encoding Default } catch { return }
}
$matches = [regex]::Matches($text, $pattern, "IgnoreCase")
$count += $matches.Count
}
Write-Output $count