dx4 v2
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
# 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
|
||||
Reference in New Issue
Block a user