# 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