From 1915afb5648316c2689c1db194e09b23ebd7b0ab Mon Sep 17 00:00:00 2001 From: Chris Donnelly Date: Thu, 30 Jan 2025 16:47:35 -0600 Subject: [PATCH 1/4] fix: relative path handling By default if you pass a relative path to the .NET APIs, it will use [Environment]::CurrentDirectory as its base, not your actual PowerShell working directory. The problem is that the two are almost never the same. This changes it so that the entry path is resolved by PowerShell, not .NET. --- PSItems/Public/Find-Item.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/PSItems/Public/Find-Item.ps1 b/PSItems/Public/Find-Item.ps1 index f90a501..413dfe1 100644 --- a/PSItems/Public/Find-Item.ps1 +++ b/PSItems/Public/Find-Item.ps1 @@ -97,7 +97,7 @@ [CmdletBinding()] [OutputType('System.String', 'System.IO.FileSystemInfo')] param ( - # Path to search for files + # Path to search for files. Defaults to current directory. [Parameter(Mandatory = $false, Position = 0)] [string] $Path = $pwd, @@ -165,6 +165,10 @@ Default { $Method = 'EnumerateFileSystemEntries' } } + # Resolve absolute path in case it is relative + [ref] $dummy = $null + $Path = $PSCmdlet.GetResolvedProviderPathFromPSPath($Path, $dummy) + try { # if more than one string was given use foreach (so if input $Name is a string array) foreach ($input in $Name) { From 4f884fc5bd350024b79232f3b903b7260b962df1 Mon Sep 17 00:00:00 2001 From: Chris Donnelly Date: Thu, 13 Feb 2025 12:54:59 -0600 Subject: [PATCH 2/4] fix: error handling for path resolution --- PSItems/Public/Find-Item.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PSItems/Public/Find-Item.ps1 b/PSItems/Public/Find-Item.ps1 index 413dfe1..41a2ae8 100644 --- a/PSItems/Public/Find-Item.ps1 +++ b/PSItems/Public/Find-Item.ps1 @@ -165,14 +165,14 @@ Default { $Method = 'EnumerateFileSystemEntries' } } - # Resolve absolute path in case it is relative - [ref] $dummy = $null - $Path = $PSCmdlet.GetResolvedProviderPathFromPSPath($Path, $dummy) - try { + # Resolve absolute path in case it is relative + [ref] $dummy = $null + $absolutePath = $PSCmdlet.GetResolvedProviderPathFromPSPath($Path, $dummy) + # if more than one string was given use foreach (so if input $Name is a string array) foreach ($input in $Name) { - foreach ($item in [System.IO.Directory]::$($Method)($path, $input, $EnumerationOptions)) { + foreach ($item in [System.IO.Directory]::$($Method)($absolutePath, $input, $EnumerationOptions)) { if ($As -eq 'FileInfo') { $file = [System.IO.FileInfo]::new($item) } else { $file = [string]::new($item) } Write-Output $file } From 4b4f8bdcd78b2acb6855e3625253f9a00d28c293 Mon Sep 17 00:00:00 2001 From: Chris Donnelly Date: Thu, 13 Feb 2025 12:55:56 -0600 Subject: [PATCH 3/4] fix: error output. PowerShell expects things to be written to Write-Error so they can be handled in a standard fashion based on the ErrorActionPreference. --- PSItems/Public/Find-Item.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PSItems/Public/Find-Item.ps1 b/PSItems/Public/Find-Item.ps1 index 41a2ae8..0118afa 100644 --- a/PSItems/Public/Find-Item.ps1 +++ b/PSItems/Public/Find-Item.ps1 @@ -178,7 +178,8 @@ } } } catch { - throw $_.Exception.Message + Write-Error $_ + return } } From 4d67a2181ab668caf575f0324c3da147bca1bfee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= Date: Fri, 5 Sep 2025 17:44:33 +0200 Subject: [PATCH 4/4] only use first element of provider returned array for now (will be changed in newer versions) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- PSItems/Public/Find-Item.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PSItems/Public/Find-Item.ps1 b/PSItems/Public/Find-Item.ps1 index 0118afa..395c2ef 100644 --- a/PSItems/Public/Find-Item.ps1 +++ b/PSItems/Public/Find-Item.ps1 @@ -168,8 +168,7 @@ try { # Resolve absolute path in case it is relative [ref] $dummy = $null - $absolutePath = $PSCmdlet.GetResolvedProviderPathFromPSPath($Path, $dummy) - + $absolutePath = $PSCmdlet.GetResolvedProviderPathFromPSPath($Path, $dummy)[0] # if more than one string was given use foreach (so if input $Name is a string array) foreach ($input in $Name) { foreach ($item in [System.IO.Directory]::$($Method)($absolutePath, $input, $EnumerationOptions)) {