1
PS D:\> Push-Location "D:\SILO\MEDIA.MASTER\MUSIC3\Eminem\Eminem - The Marshall Mathers LP [2000]"
Push-Location : Cannot find path 'D:\SILO\MEDIA.MASTER\MUSIC3\Eminem\Eminem - The Marshall Mathers LP [2000]' because it does not exist.
At line:1 char:1
+ Push-Location "D:\SILO\MEDIA.MASTER\MUSIC3\Eminem\Eminem - The Marsha ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (D:\SILO\MEDIA.M...thers LP [2000]:String) [Push-Location], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.PushLocationCommand
 

PS D:\> cd "D:\SILO\MEDIA.MASTER\MUSIC3\Eminem"

PS D:\SILO\MEDIA.MASTER\MUSIC3\Eminem> cd '.\Eminem - The Marshall Mathers LP `[2000`]'

PS D:\SILO\MEDIA.MASTER\MUSIC3\Eminem\Eminem - The Marshall Mathers LP [2000]> cd "D:\SILO\MEDIA.MASTER\MUSIC3\Eminem\Eminem - The Marshall Mathers LP [2000]"
cd : Cannot find path 'D:\SILO\MEDIA.MASTER\MUSIC3\Eminem\Eminem - The Marshall Mathers LP [2000]' because it does not exist.
At line:1 char:1
+ cd "D:\SILO\MEDIA.MASTER\MUSIC3\Eminem\Eminem - The Marshall Mathers  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (D:\SILO\MEDIA.M...thers LP [2000]:String) [Set-Location], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

You can see that both Push-Location and CD does not work but when I use CD in sections it works.

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 1
    Try ```Push-Location -LiteralPath "D:\...etc..."``` - the default parameter set is ```-Path``` which treats ```[``` and ```]``` as special characters - see https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/push-location?view=powershell-7.2. – mclayton Oct 15 '22 at 22:32
  • 1
    Note - this is *probably* a duplicate question but I can't find a good candidate right now, but here's a pretty detailed answer for a *similar* question... https://stackoverflow.com/a/57778204/3156906, and the "about_WIldcards" documentation here https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_wildcards?view=powershell-7.2 lists the behaviour of ```[``` and ```]``` in "wildcard" path parameters ) – mclayton Oct 15 '22 at 22:37
  • 1
    Thanks, @mclayton. I've generalized the answer that I've marked this question as a duplicate of; said answer can now hopefully generally serve as a closure target for similar `-Path` / `-LiteralPath` problem, irrespective of the specific cmdlet in which the problem arises. – mklement0 Oct 15 '22 at 22:51
  • 1
    -LiteralPath worked well, there were still a couple of paths failing but I think those are a path length issue. – JPPintoDotCom Oct 16 '22 at 01:15
  • 1
    @mklement0 - – mclayton Oct 16 '22 at 10:59

0 Answers0