You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Resolve-Path -RelativeBasePath is ignored unless -Relative is also specified, should imply the latter #20920
changed the title [-]Resolve-Path -RelativeBasePath is ignored unless -Relative is also specified, should imply the latter[/-][+]`Resolve-Path -RelativeBasePath` is ignored unless `-Relative` is also specified, should imply the latter[/+]on Dec 14, 2023
Thanks, MartinGC94, I wasn't aware of this feature.
Let me try to summarize, as the basis for discussing potential changes / amending the documentation:
-RelativeBasePath has two distinct use cases - one with and the other without also specifying -Relative.
In both cases, -RelativeBasePath acts as a reference path for the resolution.
With-Relative:
Returns relative paths, as strings, which describes how to get from the input paths to the reference path (which defaults to the current location), using . and .. components as needed.
This is equally useful for both relative and absolute input paths, but it is important to note that a relative input path is interpreted as relative to -RelativeBasePath.
Examples (using literal paths, but wildcards are supported, via -Path):
# ABSOLUTE input path:# Get the relative path from C:\Windows to, say, C:\Users\jdoe -> '..\Users\jdoe'Resolve-Path$HOME-Relative -RelativeBasePath C:\Windows
# RELATIVE input path: # Get the relative path from C:\Windows to C:\Windows\System32 -> '.\System32'Resolve-Path System32 -Relative -RelativeBasePath C:\Windows
# This is basically the equivalent of:# '.\' + (Get-Item (Join-Path C:\Windows System32)).Name
Without-Relative:
Returns absolute paths, as [System.Management.Automation.PathInfo] instances.
This parameter combination It is therefore only useful with relative input paths, given that there'd be nothing to resolve for absolute ones.
Example:
# Get the absolute paths of items named Prog* in C:\# -> [System.Management.Automation.PathInfo] instances for the following full paths:# 'C:\Program Files'# 'C:\Program Files (x86)'Resolve-Path Prog*-RelativeBasePath C:\
# This is the equivalent of:# Resolve-Path (Join-Path C:\ Prog*)
Potential resolutions:
The docs definitely need amending, at the very least to modify the useless Resolve-Path -Path $ExecutablePath -RelativeBasePath $env:TEMP example, which uses an absolute input path.
Given that Resolve-Path Prog* -RelativeBasePath C:\ is essentially the same as Resolve-Path (Join-Path C:\ Prog*), maybe we could have done without the former, especially given the potential for confusion around -Relative - but I guess that ship has sailed.
To lessen the potential for confusion, I suggest renaming -RelativeBasePath to -BasePath (and keeping the former a as an alias of the latter, for backward compatibility):
This avoids the expectation that -RelativeBasePath use implies-Relative (which is what prompted creation of this issue).
By avoiding the word Relative in the name, users will be less tempted to think that the feature relateds exclusively to the -Relative switch.
Activity
[-]Resolve-Path -RelativeBasePath is ignored unless -Relative is also specified, should imply the latter[/-][+]`Resolve-Path -RelativeBasePath` is ignored unless `-Relative` is also specified, should imply the latter[/+]MartinGC94 commentedon Dec 14, 2023
That was the initial implementation but I changed it here: #19755 so people could resolve a relative path to a full path like this:
Of course it's not very useful when you are specifying a full path as the input but we can't do anything about that.
mklement0 commentedon Dec 14, 2023
Thanks, MartinGC94, I wasn't aware of this feature.
Let me try to summarize, as the basis for discussing potential changes / amending the documentation:
-RelativeBasePathhas two distinct use cases - one with and the other without also specifying-Relative.In both cases,
-RelativeBasePathacts as a reference path for the resolution.With
-Relative:.and..components as needed.-RelativeBasePath.-Path):Without
-Relative:Returns absolute paths, as
[System.Management.Automation.PathInfo]instances.This parameter combination It is therefore only useful with relative input paths, given that there'd be nothing to resolve for absolute ones.
Example:
Potential resolutions:
The docs definitely need amending, at the very least to modify the useless
Resolve-Path -Path $ExecutablePath -RelativeBasePath $env:TEMPexample, which uses an absolute input path.Given that
Resolve-Path Prog* -RelativeBasePath C:\is essentially the same asResolve-Path (Join-Path C:\ Prog*), maybe we could have done without the former, especially given the potential for confusion around-Relative- but I guess that ship has sailed.To lessen the potential for confusion, I suggest renaming
-RelativeBasePathto-BasePath(and keeping the former a as an alias of the latter, for backward compatibility):-RelativeBasePathuse implies-Relative(which is what prompted creation of this issue).Relativein the name, users will be less tempted to think that the feature relateds exclusively to the-Relativeswitch.mklement0 commentedon Dec 15, 2023
So that this issue doesn't die a slow death (which may still happen to the linked feature request), I'm closing this in favor of:
A documentation bug report based on the above: Incorrect syntax diagrams, unhelpful
-RelativeBasePathexample; need for clarification of the latter's functionality MicrosoftDocs/PowerShell-Docs#10738A feature request to rename the parameter:
Resolve-Path: Rename-RelativeBasePathto-BasePath#20937microsoft-github-policy-service commentedon Dec 15, 2023
📣 Hey Michael Klement (@mklement0), how did we do? We would love to hear your feedback with the link below! 🗣️
🔗 https://aka.ms/PSRepoFeedback