Updated search-files.ps1

This commit is contained in:
Markus Fleschutz 2025-05-14 07:58:51 +02:00
parent 09eb3d1808
commit 1401302301

View File

@ -23,14 +23,15 @@
param([string]$textPattern = "", [string]$filePattern = "") param([string]$textPattern = "", [string]$filePattern = "")
function ListLocations { param([string]$textPattern, [string]$filePattern) function ListLocations { param([string]$textPattern, [string]$filePattern)
$files = Get-Item $filePattern
$list = Select-String -path $filePattern -pattern "$textPattern" $list = Select-String -path $filePattern -pattern "$textPattern"
foreach($item in $list) { New-Object PSObject -Property @{ 'FILE'="$($item.Path)"; 'LINE'="$($item.LineNumber):$($item.Line)" } } foreach($item in $list) { New-Object PSObject -Property @{ 'FILE'="$($item.Path)"; 'LINE'="$($item.LineNumber):$($item.Line)" } }
"✅ Found $($list.Count) lines containing '$textPattern' in $filePattern." "✅ Found $($list.Count) lines in $($files.Count) files containing '$textPattern'."
} }
try { try {
if ($textPattern -eq "" ) { $textPattern = Read-Host "Enter the text pattern, e.g. 'UFO'" } if ($textPattern -eq "" ) { $textPattern = Read-Host "Enter the text pattern (e.g. ALIEN)" }
if ($filePattern -eq "" ) { $filePattern = Read-Host "Enter the file pattern, e.g. '*.ps1'" } if ($filePattern -eq "" ) { $filePattern = Read-Host "Enter the file pattern (e.g. *.txt)" }
ListLocations $textPattern $filePattern | Format-Table -property FILE,LINE -autoSize ListLocations $textPattern $filePattern | Format-Table -property FILE,LINE -autoSize
exit 0 # success exit 0 # success