Skip to content

Commit 35e940a

Browse files
committed
Rename folder Data to data
1 parent 8932737 commit 35e940a

109 files changed

Lines changed: 16 additions & 17 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Scripts/replace-in-files.ps1

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
<#
1+
<#
22
.SYNOPSIS
33
Search and replace a pattern in the given files by the replacement
44
.DESCRIPTION
55
This PowerShell script searches and replaces a pattern in the given files by the replacement.
66
.PARAMETER pattern
7-
Specifies the pattern to look for
7+
Specifies the text pattern to look for
88
.PARAMETER replacement
9-
Specifies the replacement
10-
.PARAMETER files
9+
Specifies the text replacement
10+
.PARAMETER filePattern
1111
Specifies the file to scan
1212
.EXAMPLE
1313
PS> ./replace-in-files NSA "No Such Agency" C:\Temp\*.txt
@@ -17,28 +17,27 @@
1717
Author: Markus Fleschutz | License: CC0
1818
#>
1919

20-
param([string]$pattern = "", [string]$replacement = "", [string]$files = "")
20+
param([string]$pattern = "", [string]$replacement = "", [string]$filePattern = "")
2121

22-
function ReplaceInFile { param([string]$FilePath, [string]$Pattern, [string]$Replacement)
22+
function ReplaceInFile { param([string]$path, [string]$pattern, [string]$replacement)
2323

24-
[System.IO.File]::WriteAllText($FilePath,
25-
([System.IO.File]::ReadAllText($FilePath) -replace $Pattern, $Replacement)
24+
[System.IO.File]::WriteAllText($path,
25+
([System.IO.File]::ReadAllText($path) -replace $pattern, $replacement)
2626
)
2727
}
2828

2929
try {
30-
if ($pattern -eq "" ) { $pattern = read-host "Enter search pattern" }
31-
if ($replacement -eq "" ) { $replacement = read-host "Enter replacement" }
32-
if ($files -eq "" ) { $files = read-host "Enter files" }
30+
if ($pattern -eq "" ) { $pattern = Read-Host "Enter the text pattern to look for" }
31+
if ($replacement -eq "" ) { $replacement = Read-Host "Enter the text replacement" }
32+
if ($filePattern -eq "" ) { $filePattern = Read-Host "Enter the file pattern" }
3333

34-
$StopWatch = [system.diagnostics.stopwatch]::startNew()
35-
36-
$fileList = (get-childItem -path "$files" -attributes !Directory)
37-
foreach($file in $fileList) {
34+
$stopWatch = [system.diagnostics.stopwatch]::startNew()
35+
$files = (Get-ChildItem -path "$filePattern" -attributes !Directory)
36+
foreach($file in $files) {
3837
ReplaceInFile $file $pattern $replacement
3938
}
40-
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
41-
"OK, replaced '$pattern' by '$replacement' in $($fileList.Count) files in $Elapsed sec."
39+
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
40+
"✔️ Replaced '$pattern' by '$replacement' in $($files.Count) files in $elapsed sec"
4241
exit 0 # success
4342
} catch {
4443
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

0 commit comments

Comments
 (0)