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

Find-Item: relative paths are resolved to the wrong directory #19

Open
cdonnellytx opened this issue Jan 30, 2025 · 0 comments
Open

Find-Item: relative paths are resolved to the wrong directory #19

cdonnellytx opened this issue Jan 30, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@cdonnellytx
Copy link

When specifying a relative path to -Path, it is resolved to the wrong current directory, frequently resulting in errors like the following:

Exception calling "EnumerateFileSystemEntries" with "3" argument(s): "Could not find a part of the path C:\Users\cdonnelly\foo.

Expected Behavior

Find-Item -Path "foo" should crawl "$PWD\foo".

Current Behavior

Find-Item -Path "foo" crawls "$([System.Environment]::CurrentDirectory)\foo", throwing an error if it is not found.

Possible Solution

Resolve the path using PowerShell APIs. See #18 .

Steps to Reproduce (for bugs)

  1. Set-Location to any filesystem directory that isn't [System.Environment]::CurrentDirectory. In practice this means "not $HOME".
  2. Call Find-Item foo where foo is a relative path that exists in the test location but ideally not in $HOME either.

A more formal example:

# we need a temporary dir, unfortunately APIs only let us create temporary files.
# Fortunately I have a workaround.
New-TemporaryFile | % { rm $_; mkdir $_ } | Set-Location

# now we need a child with a unique name too.  Using a Guid since it **should** be unique.
$path = [Guid]::NewGuid().ToString()
mkdir $path

# Put a file in the new directory for good measure
echo '' > (Join-Path ${path} 'foo.txt')

# Now find.
Find-Item -Path $path

Context

Your Environment

  • Module version used: 0.3.6
  • Operating System and PowerShell version: Microsoft Windows 10.0.26100 (24H2) x64, PowerShell 7.4.x and 7.5.0.
@cdonnellytx cdonnellytx added the bug Something isn't working label Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant