question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[System.IO.Path]::GetFullPath with a relative path is not honoring the current working directory as documented

See original GitHub issue

Steps to reproduce

# CD to user home directory then call GetFullPath with a relative path
cd; [System.IO.Path]::GetFullPath("path")

Expected behavior

Per the documentation for GetFullPath and the behavior in Windows PowerShell:

C:\Users\<USER>\path

Actual behavior

A path relative to "c:\windows\system32" is returned regardless of the current working directory.

C:\WINDOWS\system32\path

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.2
PSEdition                      Core
GitCommitId                    7.0.0-preview.2
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
djhaskin987commented, Nov 29, 2022
[IO.Path]::GetFullPath([IO.Path]::Combine((Get-Location -PSProvider FileSystem).ProviderPath, $path))

That works on PS 5.1 . @hunandy14 ^^^

1reaction
mikebattistacommented, Aug 1, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Path.GetFullPath Method (System.IO)
If path is a relative path, this overload returns a fully qualified path that can be based on the current drive and current...
Read more >
How to get relative path from absolute path
So I would prefer to show the file path relative to the assembly/exe directory. For example, the assembly resides at C:\Program Files\Dummy ...
Read more >
C# relative, absolute path - Microsoft Q&A
Hello, why is not workling? I use relative path. ToXMLFile($@"..\..\Data\Orders\{CurrentOrderSerials.OrderId}.xml"); public static void ...
Read more >
Relative file paths, and the .NET adapter. - NI Community
The current working directory is set by the open file dialog when you browse to a specific directory and by many other things...
Read more >
Type: System.IO.Path
A path can contain absolute or relative location information. Absolute paths fully specify a location: the file or directory can be uniquely identified ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found