mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-02-08 22:10:14 +01:00
Improve replace-in-files.ps1
This commit is contained in:
parent
61e76dea6a
commit
a5ae44db68
@ -25,9 +25,14 @@ try {
|
|||||||
if ($replacement -eq "" ) { $replacement = read-host "Enter replacement" }
|
if ($replacement -eq "" ) { $replacement = read-host "Enter replacement" }
|
||||||
if ($files -eq "" ) { $files = read-host "Enter files" }
|
if ($files -eq "" ) { $files = read-host "Enter files" }
|
||||||
|
|
||||||
foreach($file in $files) {
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
|
|
||||||
|
$fileList = (get-childItem -path "$files" -attributes !Directory)
|
||||||
|
foreach($file in $fileList) {
|
||||||
ReplaceInFile $file $pattern $replacement
|
ReplaceInFile $file $pattern $replacement
|
||||||
}
|
}
|
||||||
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||||
|
"✔️ replaced '$pattern' by '$replacement' in $($Files.Count) files in $Elapsed sec"
|
||||||
exit 0
|
exit 0
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
||||||
|
Loading…
Reference in New Issue
Block a user