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
Split-Path switches (-Leaf, -Parent, ...) do not work with -LiteralPath #8751
Note: This affects all switches supported by Split-Path; combining them with the (implied) -Path works fine, but with -LiteralPath the parameter set cannot be resolved.
foo
Parameter set cannot be resolved using the specified named parameters. ...
Parameter set cannot be resolved using the specified named parameters. ...
Environment data
PowerShell Core v6.2.0-preview.3 on macOS 10.14.2
PowerShell Core v6.2.0-preview.3 on Ubuntu 18.04.1 LTS
PowerShell Core v6.2.0-preview.3 on Microsoft Windows 10 Pro (64-bit; Version 1803, OS Build: 17134.471)
Windows PowerShell v5.1.17134.407 on Microsoft Windows 10 Pro (64-bit; Version 1803, OS Build: 17134.471)
changed the title [-][BUG] Split-Path switches (-Leaf, -Parent, ...) do not work with -LiteralPath[/-][+]Split-Path switches (-Leaf, -Parent, ...) do not work with -LiteralPath[/+]on Feb 2, 2019
It looks like the workaround is to simply use -Path, which - unlike with other cmdlets - doesn't actually treat its argument as a wildcard pattern in the case of Split-Path; in other words: -Path apparently acts the way that -LiteralPath normally does.
but i have a path like date\matter\movva, jagadeesh [jagadeesh408] and if i am using -path to get the leaf it is skipping the result due to the special characters [].
When i am using -literalpath for removing the leaf from the path it is working fine but not for getting the leaf
I am using this way
split-Path -path "'$($filepaths1[$i])'" -Leaf -Resolve
where $filepaths1 is array of different paths and getting the error as below
split-Path : Cannot find drive. A drive with the name ''D' does not exist.
when i am using the command only with single quotes as below, it is not taking the variable also as string
Do not enclose the file path in embedded' characters - such a path won't be valid; also don't use ' as the syntactic quotes, for the reasons you state (single-quoted strings are verbatim strings).
Just use the expression as-is, without quoting:
split-Path-path $filepaths1[$i] -Leaf -Resolve
If you want to use -Resolve, you actually must use -Path, not -LiteralPath (which is strange in itself).
if i am using this
split-Path -path $filepaths1[$i] -Leaf -Resolve
whenever $filepaths1 have a path like date\matter\movva, jagadeesh [jagadeesh408] with special characters like [], it is skipping the result and providing me the null results
(Correction to my earlier comment, which I removed.)
Since you're only looking for the leaf (file name) component, simply omit the -Resolve part, which prevents the unwanted interpretation of the input paths as wildcard expressions:
split-Path-path $filepaths1[$i] -Leaf
That said, it does make sense to combine -Resolve with -LiteralPath as well, namely to expand the - literal, but possibly relative - path to a full path before extracting the part of interest.
For instance, you may want to use -Qualifier to extract the drive spec. from a literal path specified as a relative path (without -Resolve, the relative path would be interpreted as-is, and therefore has no drive spec.); this is currently impossible:
# !! Currently fails, due to the bug at hand.Split-Path-LiteralPath file.txt -Resolve -Qualifier
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
Activity
[-][BUG] Split-Path switches (-Leaf, -Parent, ...) do not work with -LiteralPath[/-][+]Split-Path switches (-Leaf, -Parent, ...) do not work with -LiteralPath[/+]jagadeesh408 commentedon Jun 1, 2020
I am also facing the same issue. Does this issues resolved?
If yes, can someone guide me on the solution
mklement0 commentedon Jun 1, 2020
It looks like the workaround is to simply use
-Path, which - unlike with other cmdlets - doesn't actually treat its argument as a wildcard pattern in the case ofSplit-Path; in other words:-Pathapparently acts the way that-LiteralPathnormally does.jagadeesh408 commentedon Jun 1, 2020
but i have a path like date\matter\movva, jagadeesh [jagadeesh408] and if i am using -path to get the leaf it is skipping the result due to the special characters [].
When i am using -literalpath for removing the leaf from the path it is working fine but not for getting the leaf
mklement0 commentedon Jun 1, 2020
I don't see this behavior (neither in WinPS 5.1, nor in 7.0, nor in 7.1.0-preview.3); do you get a different result, or am I missing something?
jagadeesh408 commentedon Jun 1, 2020
I am using this way
split-Path -path "'$($filepaths1[$i])'" -Leaf -Resolve
where $filepaths1 is array of different paths and getting the error as below
split-Path : Cannot find drive. A drive with the name ''D' does not exist.
when i am using the command only with single quotes as below, it is not taking the variable also as string
split-Path -path '$($filepaths1[$i])' -Leaf -Resolve
mklement0 commentedon Jun 1, 2020
Do not enclose the file path in embedded
'characters - such a path won't be valid; also don't use'as the syntactic quotes, for the reasons you state (single-quoted strings are verbatim strings).Just use the expression as-is, without quoting:
If you want to use
-Resolve, you actually must use-Path, not-LiteralPath(which is strange in itself).jagadeesh408 commentedon Jun 1, 2020
if i am using this
split-Path -path $filepaths1[$i] -Leaf -Resolve
whenever $filepaths1 have a path like date\matter\movva, jagadeesh [jagadeesh408] with special characters like [], it is skipping the result and providing me the null results
mklement0 commentedon Jun 1, 2020
(Correction to my earlier comment, which I removed.)
Since you're only looking for the leaf (file name) component, simply omit the
-Resolvepart, which prevents the unwanted interpretation of the input paths as wildcard expressions:That said, it does make sense to combine
-Resolvewith-LiteralPathas well, namely to expand the - literal, but possibly relative - path to a full path before extracting the part of interest.For instance, you may want to use
-Qualifierto extract the drive spec. from a literal path specified as a relative path (without-Resolve, the relative path would be interpreted as-is, and therefore has no drive spec.); this is currently impossible:jagadeesh408 commentedon Jun 1, 2020
Thanks,
I will test it and update the thread if any issues
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.