Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: relative path handling in Find-Item #18

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions PSItems/Public/Find-Item.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -166,15 +166,20 @@
}

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
}
}
} catch {
throw $_.Exception.Message
Write-Error $_
return
}
}

Expand Down