Skip to content

Commit 4ab1d3f

Browse files
committed
Release 1.218.2025
1 parent f60f260 commit 4ab1d3f

4 files changed

Lines changed: 73 additions & 16 deletions

File tree

Functions/GenXdev.FileSystem/Rename-InProject.ps1

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
###############################################################################
22
<#
33
.SYNOPSIS
4-
Performs case-sensitive text replacement throughout a project directory.
4+
Performs text replacement throughout a project directory.
55
66
.DESCRIPTION
77
Recursively searches through files and directories in a project to perform text
88
replacements. Handles both file/directory names and file contents. Skips common
99
binary files and repository folders (.git, .svn) to avoid corruption. Uses UTF-8
10-
encoding without BOM for file operations.
10+
encoding without BOM for file operations. Supports both case-sensitive and
11+
case-insensitive replacement modes.
1112
1213
.PARAMETER Source
1314
The directory, filepath, or directory+searchmask to process. Defaults to current
1415
directory if not specified.
1516
1617
.PARAMETER FindText
17-
The case-sensitive text pattern to search for in filenames and content.
18+
The text pattern to search for in filenames and content. Case sensitivity is
19+
controlled by the CaseInsensitive parameter.
1820
1921
.PARAMETER ReplacementText
2022
The text to replace all instances of FindText with.
2123
24+
.PARAMETER CaseInsensitive
25+
Perform case-insensitive text replacement. When specified, matching is done
26+
without regard to case.
27+
2228
.PARAMETER WhatIf
2329
Shows what changes would occur without actually making them.
2430
@@ -28,6 +34,9 @@ Rename-InProject -Source .\src\*.js -FindText "oldName" `
2834
2935
.EXAMPLE
3036
rip . "MyClass" "MyNewClass" -WhatIf
37+
38+
.EXAMPLE
39+
rip . "OLDNAME" "NewName" -CaseInsensitive
3140
#>
3241
function Rename-InProject {
3342

@@ -49,7 +58,7 @@ function Rename-InProject {
4958
Mandatory = $true,
5059
Position = 1,
5160
ValueFromPipeline = $false,
52-
HelpMessage = 'The text to find (case sensitive)'
61+
HelpMessage = 'The text to find (case sensitivity controlled by CaseInsensitive parameter)'
5362
)]
5463
[Alias('find', 'what', 'from')]
5564
[ValidateNotNullOrEmpty()]
@@ -63,7 +72,14 @@ function Rename-InProject {
6372
)]
6473
[Alias('into', 'txt', 'to')]
6574
[ValidateNotNull()]
66-
[string] $ReplacementText
75+
[string] $ReplacementText,
76+
########################################################################
77+
[Parameter(
78+
Mandatory = $false,
79+
ValueFromPipeline = $false,
80+
HelpMessage = 'Perform case-insensitive text replacement'
81+
)]
82+
[switch] $CaseInsensitive
6783
########################################################################
6884
)
6985

@@ -161,7 +177,14 @@ function Rename-InProject {
161177
# replace text in file contents
162178
$content = [IO.File]::ReadAllText($filePath,
163179
[Text.Encoding]::UTF8)
164-
$newContent = $content.Replace($FindText, $ReplacementText)
180+
181+
if ($CaseInsensitive) {
182+
$newContent = $content.Replace($FindText, $ReplacementText,
183+
[StringComparison]::OrdinalIgnoreCase)
184+
}
185+
else {
186+
$newContent = $content.Replace($FindText, $ReplacementText)
187+
}
165188

166189
if ($content -ne $newContent) {
167190
if ($PSCmdlet.ShouldProcess($filePath,
@@ -181,7 +204,13 @@ function Rename-InProject {
181204

182205
# handle filename changes
183206
$oldName = [IO.Path]::GetFileName($filePath)
184-
$newName = $oldName.Replace($FindText, $ReplacementText)
207+
if ($CaseInsensitive) {
208+
$newName = $oldName.Replace($FindText, $ReplacementText,
209+
[StringComparison]::OrdinalIgnoreCase)
210+
}
211+
else {
212+
$newName = $oldName.Replace($FindText, $ReplacementText)
213+
}
185214

186215
if ($oldName -ne $newName) {
187216
$newPath = [IO.Path]::Combine(
@@ -223,7 +252,13 @@ function Rename-InProject {
223252

224253
$dir = $_
225254
$oldName = $dir.Name
226-
$newName = $oldName.Replace($FindText, $ReplacementText)
255+
if ($CaseInsensitive) {
256+
$newName = $oldName.Replace($FindText, $ReplacementText,
257+
[StringComparison]::OrdinalIgnoreCase)
258+
}
259+
else {
260+
$newName = $oldName.Replace($FindText, $ReplacementText)
261+
}
227262

228263
if ($oldName -ne $newName) {
229264
$newPath = GenXdev.FileSystem\Expand-Path (

GenXdev.FileSystem.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Generated by: genXdev
55
#
6-
# Generated on: 25/07/2025
6+
# Generated on: 26/07/2025
77
#
88

99
@{
@@ -12,7 +12,7 @@
1212
RootModule = 'GenXdev.FileSystem.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '1.216.2025'
15+
ModuleVersion = '1.218.2025'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = 'Core'

README.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Update-Module
120120
| [Remove-AllItems](#Remove-AllItems) | sdel | Recursively removes all content from a directory with advanced error handling. |
121121
| [Remove-ItemWithFallback](#Remove-ItemWithFallback) | rmf | Removes files or directories with multiple fallback mechanisms for reliable deletion. |
122122
| [Remove-OnReboot](#Remove-OnReboot) | | Marks files or directories for deletion during the next system boot. |
123-
| [Rename-InProject](#Rename-InProject) | rip | Performs case-sensitive text replacement throughout a project directory. |
123+
| [Rename-InProject](#Rename-InProject) | rip | Performs text replacement throughout a project directory. |
124124
| [ResolveInputObjectFileNames](#ResolveInputObjectFileNames) | | |
125125
| [Start-RoboCopy](#Start-RoboCopy) | xc, rc | Provides a PowerShell wrapper for Microsoft's Robust Copy (RoboCopy) utility. |
126126
@@ -1182,18 +1182,19 @@ NAME
11821182
Rename-InProject
11831183
11841184
SYNOPSIS
1185-
Performs case-sensitive text replacement throughout a project directory.
1185+
Performs text replacement throughout a project directory.
11861186
11871187
11881188
SYNTAX
1189-
Rename-InProject [[-Source] <String>] [-FindText] <String> [-ReplacementText] <String> [-WhatIf] [-Confirm] [<CommonParameters>]
1189+
Rename-InProject [[-Source] <String>] [-FindText] <String> [-ReplacementText] <String> [-CaseInsensitive] [-WhatIf] [-Confirm] [<CommonParameters>]
11901190
11911191
11921192
DESCRIPTION
11931193
Recursively searches through files and directories in a project to perform text
11941194
replacements. Handles both file/directory names and file contents. Skips common
11951195
binary files and repository folders (.git, .svn) to avoid corruption. Uses UTF-8
1196-
encoding without BOM for file operations.
1196+
encoding without BOM for file operations. Supports both case-sensitive and
1197+
case-insensitive replacement modes.
11971198
11981199
11991200
PARAMETERS
@@ -1209,7 +1210,8 @@ PARAMETERS
12091210
Accept wildcard characters? false
12101211
12111212
-FindText <String>
1212-
The case-sensitive text pattern to search for in filenames and content.
1213+
The text pattern to search for in filenames and content. Case sensitivity is
1214+
controlled by the CaseInsensitive parameter.
12131215
12141216
Required? true
12151217
Position? 2
@@ -1228,6 +1230,17 @@ PARAMETERS
12281230
Aliases
12291231
Accept wildcard characters? false
12301232
1233+
-CaseInsensitive [<SwitchParameter>]
1234+
Perform case-insensitive text replacement. When specified, matching is done
1235+
without regard to case.
1236+
1237+
Required? false
1238+
Position? named
1239+
Default value False
1240+
Accept pipeline input? false
1241+
Aliases
1242+
Accept wildcard characters? false
1243+
12311244
-WhatIf [<SwitchParameter>]
12321245
Shows what changes would occur without actually making them.
12331246
@@ -1276,6 +1289,15 @@ OUTPUTS
12761289
12771290
12781291
1292+
-------------------------- EXAMPLE 3 --------------------------
1293+
1294+
PS > rip . "OLDNAME" "NewName" -CaseInsensitive
1295+
1296+
1297+
1298+
1299+
1300+
12791301
12801302
RELATED LINKS
12811303

Tests/GenXdev.FileSystem/Find-Item.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ $message
341341

342342
Pester\It 'Should match the pattern' {
343343

344-
$found = @(GenXdev.FileSystem\Find-Item -SearchMask "$PSScriptRoot\..\..\..\..\..\**\Genx*stem\1.216.2025\Functions\GenXdev.FileSystem\*.ps1" -PassThru | Microsoft.PowerShell.Utility\Select-Object -ExpandProperty FullName)
344+
$found = @(GenXdev.FileSystem\Find-Item -SearchMask "$PSScriptRoot\..\..\..\..\..\**\Genx*stem\1.218.2025\Functions\GenXdev.FileSystem\*.ps1" -PassThru | Microsoft.PowerShell.Utility\Select-Object -ExpandProperty FullName)
345345

346346
$found | Pester\Should -Contain (GenXdev.FileSystem\Expand-Path "$PSScriptRoot\..\..\Functions\GenXdev.FileSystem\_EnsureTypes.ps1")
347347
$found | Pester\Should -Contain (GenXdev.FileSystem\Expand-Path "$PSScriptRoot\..\..\Functions\GenXdev.FileSystem\EnsurePester.ps1")

0 commit comments

Comments
 (0)