-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
[System.IO.Path]::GetFullPath with a relative path is not honoring the current working directory as documented #10278
Comments
None of the .NET internal/integral methods recognize the current $PWD to the best of my knowledge. My first experience with this was with the [XML.Document] Save() method. |
I wouldn't be surprised if Windows PowerShell behaves the same, just happens to set the current .NET directory differently. Just checked it, actually, and using PowerShell Set-Location commands does not affect the current directory from .NET's end. Windows PowerShell does however set the initial location differently. So this is the same in Windows PS, just with different initial locations between winPS and Core |
Please see #3428. The short of it:
|
Ok. I see there is an open doc issue for this. Would be nice to see this captured somewhere discoverable as while always converting to absolute paths works that's not obvious or natural if you haven't been burned by this before. |
@vexx32, the difference is in the setting of the This is one of those items 'Hey, you can just access the entire .NET subsystem...', 'Yes, ...but there are so many thing you will need to learn first!' |
@mklement0, just found out |
The short of it is: To pass not-yet-extant paths (PowerShell Core only, because only .NET Core supports the
To be fully robust, you additionally need to guard against the current location not being a filesystem location:
The latter should work in all scenarios - but it doesn't exactly roll off the tongue. |
Hi Please if there is any alternative to solve it. Cannot find overload and argument count for 'GetFullPath': '2'.
at line:1 character:1
+ [IO.Path]::GetFullPath($path, $PWD.ProviderPath)
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest |
[IO.Path]::GetFullPath([IO.Path]::Combine((Get-Location -PSProvider FileSystem).ProviderPath, $path)) That works on PS 5.1 . |
@djhaskin987 |
Steps to reproduce
Expected behavior
Per the documentation for GetFullPath and the behavior in Windows PowerShell:
Actual behavior
A path relative to "c:\windows\system32" is returned regardless of the current working directory.
Environment data
The text was updated successfully, but these errors were encountered: