Skip to content

Commit 5997a65

Browse files
committed
Release 1.202.2025
1 parent 4ea4b65 commit 5997a65

27 files changed

Lines changed: 3348 additions & 1629 deletions
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
###############################################################################
1+
###############################################################################
22
<#
33
.SYNOPSIS
44
Ensures Pester testing framework is available for use.
@@ -11,8 +11,8 @@ Pester testing capabilities are available when needed.
1111
1212
.EXAMPLE
1313
EnsurePester
14-
###############################################################################This ensures Pester is installed and ready for use
15-
###############################################################################>
14+
This ensures Pester is installed and ready for use
15+
#>
1616
function EnsurePester {
1717

1818
[CmdletBinding()]
@@ -21,11 +21,11 @@ function EnsurePester {
2121
begin {
2222

2323
# inform user that we're checking pester installation
24-
Microsoft.PowerShell.Utility\Write-Verbose "Checking for Pester module installation..."
24+
Microsoft.PowerShell.Utility\Write-Verbose 'Checking for Pester module installation...'
2525
}
2626

2727

28-
process {
28+
process {
2929

3030
# attempt silent import of pester to check if it's available
3131
Microsoft.PowerShell.Core\Import-Module -Name Pester -ErrorAction SilentlyContinue
@@ -36,8 +36,8 @@ process {
3636
if ((-not $found) -or ($found.Version -lt '5.7.0')) {
3737

3838
# notify about installation attempt through verbose and regular output
39-
Microsoft.PowerShell.Utility\Write-Verbose "Pester module not found, attempting installation..."
40-
Microsoft.PowerShell.Utility\Write-Host "Pester not found. Installing Pester..."
39+
Microsoft.PowerShell.Utility\Write-Verbose 'Pester module not found, attempting installation...'
40+
Microsoft.PowerShell.Utility\Write-Host 'Pester not found. Installing Pester...'
4141

4242
try {
4343
# install pester module from the powershell gallery
@@ -49,22 +49,21 @@ process {
4949
$null = Microsoft.PowerShell.Core\Import-Module -Name Pester -Force
5050

5151
# confirm successful installation
52-
Microsoft.PowerShell.Utility\Write-Host "Pester installed successfully."
53-
Microsoft.PowerShell.Utility\Write-Verbose "Pester module installation and import completed."
52+
Microsoft.PowerShell.Utility\Write-Host 'Pester installed successfully.'
53+
Microsoft.PowerShell.Utility\Write-Verbose 'Pester module installation and import completed.'
5454
}
5555
catch {
5656
# report any installation failures
5757
Microsoft.PowerShell.Utility\Write-Error "Failed to install Pester. Error: $PSItem"
58-
Microsoft.PowerShell.Utility\Write-Verbose "Pester installation failed with error."
58+
Microsoft.PowerShell.Utility\Write-Verbose 'Pester installation failed with error.'
5959
}
6060
}
6161
else {
6262
# inform that pester is already available
63-
Microsoft.PowerShell.Utility\Write-Verbose "Pester module already installed and imported."
63+
Microsoft.PowerShell.Utility\Write-Verbose 'Pester module already installed and imported.'
6464
}
6565
}
6666

6767
end {
6868
}
69-
}
70-
###############################################################################
69+
}

Functions/GenXdev.FileSystem/Expand-Path.ps1

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
###############################################################################
1+
###############################################################################
22
<#
33
.SYNOPSIS
44
Expands any given file reference to a full pathname.
@@ -21,11 +21,11 @@ Expand-Path -FilePath ".\myfile.txt" -CreateFile
2121
2222
.EXAMPLE
2323
ep ~\documents\test.txt -CreateFile
24-
###############################################################################>
24+
#>
2525
function Expand-Path {
2626

2727
[CmdletBinding()]
28-
[Alias("ep")]
28+
[Alias('ep')]
2929

3030
param(
3131
########################################################################
@@ -34,44 +34,44 @@ function Expand-Path {
3434
Position = 0,
3535
ValueFromPipeline = $true,
3636
ValueFromPipelineByPropertyName = $true,
37-
HelpMessage = "Path to expand"
37+
HelpMessage = 'Path to expand'
3838
)]
3939
[ValidateNotNullOrEmpty()]
4040
[string] $FilePath,
4141
########################################################################
4242
[Parameter(
4343
Mandatory = $false,
44-
HelpMessage = "Will create directory if it does not exist"
44+
HelpMessage = 'Will create directory if it does not exist'
4545
)]
4646
[switch] $CreateDirectory,
4747
########################################################################
4848
[Parameter(
4949
Mandatory = $false,
50-
HelpMessage = "Will create an empty file if it does not exist"
50+
HelpMessage = 'Will create an empty file if it does not exist'
5151
)]
5252
[switch] $CreateFile,
5353
########################################################################
5454
[Parameter(
5555
Mandatory = $false,
56-
HelpMessage = "Will delete the file if it already exists"
56+
HelpMessage = 'Will delete the file if it already exists'
5757
)]
5858
[switch] $DeleteExistingFile,
5959
########################################################################
6060
[Parameter(
6161
Mandatory = $false,
62-
HelpMessage = "Will force the use of a specific drive"
62+
HelpMessage = 'Will force the use of a specific drive'
6363
)]
6464
[char] $ForceDrive = '*',
6565
########################################################################
6666
[Parameter(
6767
Mandatory = $false,
68-
HelpMessage = "Will throw if file does not exist"
68+
HelpMessage = 'Will throw if file does not exist'
6969
)]
7070
[switch] $FileMustExist,
7171
########################################################################
7272
[Parameter(
7373
Mandatory = $false,
74-
HelpMessage = "Will throw if directory does not exist"
74+
HelpMessage = 'Will throw if directory does not exist'
7575
)]
7676
[switch] $DirectoryMustExist
7777
########################################################################
@@ -80,8 +80,8 @@ function Expand-Path {
8080
begin {
8181

8282
# normalize path separators and remove double separators
83-
[string] $normalizedPath = $FilePath.Trim().Replace("\", [IO.Path]::DirectorySeparatorChar).
84-
Replace("/", [IO.Path]::DirectorySeparatorChar);
83+
[string] $normalizedPath = $FilePath.Trim().Replace('\', [IO.Path]::DirectorySeparatorChar).
84+
Replace('/', [IO.Path]::DirectorySeparatorChar);
8585

8686
if ($normalizedPath.StartsWith([IO.Path]::DirectorySeparatorChar + [IO.Path]::DirectorySeparatorChar)) {
8787

@@ -92,10 +92,10 @@ function Expand-Path {
9292
)
9393

9494
if (($ForceDrive -ne '*') -and
95-
("ABCDEFGHIJKLMNOPQRSTUVWXYZ".IndexOf(($ForceDrive -as [string]).ToUpperInvariant()) -ge 0)) {
95+
('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.IndexOf(($ForceDrive -as [string]).ToUpperInvariant()) -ge 0)) {
9696

9797
$i = $normalizedPath.IndexOf([IO.Path]::DirectorySeparatorChar, 2);
98-
$normalizedPath = $ForceDrive + ":" + (
98+
$normalizedPath = $ForceDrive + ':' + (
9999

100100
$i -lt 0 ? ([IO.Path]::DirectorySeparatorChar) : $normalizedPath.Substring($i)
101101
)
@@ -116,18 +116,18 @@ function Expand-Path {
116116
}
117117

118118

119-
process {
119+
process {
120120

121121
# expand home directory if path starts with ~
122-
if ($normalizedPath.StartsWith("~")) {
122+
if ($normalizedPath.StartsWith('~')) {
123123

124124
if (($ForceDrive -ne '*') -and
125-
("ABCDEFGHIJKLMNOPQRSTUVWXYZ".IndexOf(($ForceDrive -as [string]).ToUpperInvariant()) -ge 0)) {
125+
('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.IndexOf(($ForceDrive -as [string]).ToUpperInvariant()) -ge 0)) {
126126

127127
$i = $normalizedPath.IndexOf([IO.Path]::DirectorySeparatorChar, 1);
128-
$normalizedPath = $ForceDrive + ":" + (
128+
$normalizedPath = $ForceDrive + ':' + (
129129

130-
$i -lt 0 ? [IO.Path]::DirectorySeparatorChar + "**" + [IO.Path]::DirectorySeparatorChar : ("\**" + $normalizedPath.Substring($i))
130+
$i -lt 0 ? [IO.Path]::DirectorySeparatorChar + '**' + [IO.Path]::DirectorySeparatorChar : ('\**' + $normalizedPath.Substring($i))
131131
)
132132
}
133133
else {
@@ -138,12 +138,12 @@ process {
138138
}
139139

140140
if ((($normalizedPath.Length -gt 1) -and
141-
($normalizedPath.Substring(1, 1) -eq ":"))) {
141+
($normalizedPath.Substring(1, 1) -eq ':'))) {
142142

143143
if (($ForceDrive -ne '*') -and
144-
("ABCDEFGHIJKLMNOPQRSTUVWXYZ".IndexOf(($ForceDrive -as [string]).ToUpperInvariant()) -ge 0)) {
144+
('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.IndexOf(($ForceDrive -as [string]).ToUpperInvariant()) -ge 0)) {
145145
$i = $normalizedPath.IndexOf([IO.Path]::DirectorySeparatorChar);
146-
$normalizedPath = $ForceDrive + ":" + [IO.Path]::DirectorySeparatorChar + (($i -eq -1 -and $normalizedPath.Length -gt 2) -or $i -eq 2 ? "**" + [IO.Path]::DirectorySeparatorChar : "") + $normalizedPath.Substring(2)
146+
$normalizedPath = $ForceDrive + ':' + [IO.Path]::DirectorySeparatorChar + (($i -eq -1 -and $normalizedPath.Length -gt 2) -or $i -eq 2 ? '**' + [IO.Path]::DirectorySeparatorChar : '') + $normalizedPath.Substring(2)
147147
}
148148
else {
149149

@@ -168,24 +168,24 @@ process {
168168
$normalizedPath = [System.IO.Path]::GetFullPath($normalizedPath)
169169
}
170170
catch {
171-
Microsoft.PowerShell.Utility\Write-Verbose "Failed to normalize path, keeping original"
171+
Microsoft.PowerShell.Utility\Write-Verbose 'Failed to normalize path, keeping original'
172172
}
173173
}
174174
else {
175175

176176
if (($ForceDrive -ne '*') -and
177-
("ABCDEFGHIJKLMNOPQRSTUVWXYZ".IndexOf(($ForceDrive -as [string]).ToUpperInvariant()) -ge 0)) {
177+
('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.IndexOf(($ForceDrive -as [string]).ToUpperInvariant()) -ge 0)) {
178178

179-
if ($normalizedPath.Length -lt 2 -or $normalizedPath.Substring(1, 1) -ne ":") {
179+
if ($normalizedPath.Length -lt 2 -or $normalizedPath.Substring(1, 1) -ne ':') {
180180

181-
$newPath = $ForceDrive + ":" + [IO.Path]::DirectorySeparatorChar;
181+
$newPath = $ForceDrive + ':' + [IO.Path]::DirectorySeparatorChar;
182182

183-
while ($normalizedPath.StartsWith(".")) {
183+
while ($normalizedPath.StartsWith('.')) {
184184

185185
$i = $normalizedPath.IndexOf([IO.Path]::DirectorySeparatorChar);
186186
if ($i -lt 0) {
187187

188-
$normalizedPath = ""
188+
$normalizedPath = ''
189189
}
190190
else {
191191

@@ -199,7 +199,7 @@ process {
199199
}
200200
else {
201201

202-
$newPath += "**" + [IO.Path]::DirectorySeparatorChar + $normalizedPath
202+
$newPath += '**' + [IO.Path]::DirectorySeparatorChar + $normalizedPath
203203
}
204204

205205
$normalizedPath = $newPath
@@ -264,7 +264,7 @@ process {
264264

265265
# verify path doesn't point to existing directory
266266
if ([IO.Directory]::Exists($normalizedPath)) {
267-
throw "Cannot create file: Path refers to an existing directory"
267+
throw 'Cannot create file: Path refers to an existing directory'
268268
}
269269

270270
if (-not (GenXdev.FileSystem\Remove-ItemWithFallback -Path $normalizedPath)) {
@@ -287,13 +287,13 @@ process {
287287

288288
# verify path doesn't point to existing directory
289289
if ([IO.Directory]::Exists($normalizedPath)) {
290-
throw "Cannot create file: Path refers to an existing directory"
290+
throw 'Cannot create file: Path refers to an existing directory'
291291
}
292292

293293

294294
# create empty file if it doesn't exist
295295
if (-not [IO.File]::Exists($normalizedPath)) {
296-
$null = [IO.File]::WriteAllText($normalizedPath, "")
296+
$null = [IO.File]::WriteAllText($normalizedPath, '')
297297
Microsoft.PowerShell.Utility\Write-Verbose "Created empty file: $normalizedPath"
298298
}
299299
}
@@ -303,5 +303,4 @@ process {
303303

304304
end {
305305
}
306-
}
307-
###############################################################################
306+
}

Functions/GenXdev.FileSystem/Find-DuplicateFiles.ps1

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
###############################################################################
1+
###############################################################################
22
<#
33
.SYNOPSIS
44
Find duplicate files across multiple directories based on configurable criteria.
@@ -24,12 +24,12 @@ Find-DuplicateFiles -Paths "C:\Photos","D:\Backup\Photos"
2424
2525
.EXAMPLE
2626
"C:\Photos","D:\Backup\Photos" | fdf -DontCompareSize
27-
###############################################################################>
27+
#>
2828
function Find-DuplicateFiles {
2929

3030
[CmdletBinding()]
31-
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "")]
32-
[Alias("fdf")]
31+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '')]
32+
[Alias('fdf')]
3333

3434
param(
3535
###############################################################################
@@ -38,22 +38,21 @@ function Find-DuplicateFiles {
3838
Position = 0,
3939
ValueFromPipeline = $true,
4040
ValueFromPipelineByPropertyName = $true,
41-
HelpMessage = "One or more directory paths to search for duplicates"
41+
HelpMessage = 'One or more directory paths to search for duplicates'
4242
)]
43-
[ValidateNotNullOrEmpty()]
4443
[string[]] $Paths,
4544
###############################################################################
4645
[Parameter(
4746
Mandatory = $false,
4847
Position = 1,
49-
HelpMessage = "Skip file size comparison when grouping duplicates"
48+
HelpMessage = 'Skip file size comparison when grouping duplicates'
5049
)]
5150
[switch] $DontCompareSize,
5251
###############################################################################
5352
[Parameter(
5453
Mandatory = $false,
5554
Position = 2,
56-
HelpMessage = "Skip last modified date comparison when grouping duplicates"
55+
HelpMessage = 'Skip last modified date comparison when grouping duplicates'
5756
)]
5857
[switch] $DontCompareModifiedDate
5958
###############################################################################
@@ -90,7 +89,7 @@ function Find-DuplicateFiles {
9089
}
9190

9291

93-
process {
92+
process {
9493

9594
foreach ($path in $normalizedPaths) {
9695

@@ -100,11 +99,11 @@ process {
10099
Microsoft.PowerShell.Utility\Write-Verbose "Scanning directory for duplicates: $path"
101100

102101
# use direct .NET IO for faster recursive file enumeration
103-
[System.IO.Directory]::GetFiles($path, "*.*",
102+
[System.IO.Directory]::GetFiles($path, '*.*',
104103
[System.IO.SearchOption]::AllDirectories) |
105-
Microsoft.PowerShell.Core\ForEach-Object {
106-
$null = $allFiles.Add([System.IO.FileInfo]::new($_))
107-
}
104+
Microsoft.PowerShell.Core\ForEach-Object {
105+
$null = $allFiles.Add([System.IO.FileInfo]::new($_))
106+
}
108107
}
109108
else {
110109
Microsoft.PowerShell.Utility\Write-Warning "Skipping non-existent directory: $path"
@@ -116,15 +115,14 @@ process {
116115

117116
# group files by composite key and return only groups with duplicates
118117
$allFiles |
119-
Microsoft.PowerShell.Utility\Group-Object -Property { Get-FileKey $_ } |
120-
Microsoft.PowerShell.Core\Where-Object { $_.Count -gt 1 } |
121-
Microsoft.PowerShell.Core\ForEach-Object {
122-
# create result object for each duplicate group
123-
[PSCustomObject]@{
124-
FileName = $_.Group[0].Name
125-
Files = $_.Group
118+
Microsoft.PowerShell.Utility\Group-Object -Property { Get-FileKey $_ } |
119+
Microsoft.PowerShell.Core\Where-Object { $_.Count -gt 1 } |
120+
Microsoft.PowerShell.Core\ForEach-Object {
121+
# create result object for each duplicate group
122+
[PSCustomObject]@{
123+
FileName = $_.Group[0].Name
124+
Files = $_.Group
125+
}
126126
}
127-
}
128127
}
129-
}
130-
###############################################################################
128+
}

0 commit comments

Comments
 (0)