我是一个Powershell新手,试图在一个特定的文件夹上运行Get。我计划先导航到文件夹,但得到了一个错误:
PS C:\Users\pjmmc\Documents\Genealogy\Family Tree Files> cd "McNab [A1]"
cd : Cannot find path 'McNab [A1]' because it does not exist.
At line:1 char:1
+ cd "McNab [A1]"
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (McNab [A1]:String) [Set-Location], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommandMcNab A1文件夹确实存在。
Get-ChildItem也有一个问题。
PS C:\Users\pjmmc\Documents\Genealogy\Family Tree Files> dir "McNab [A1]"
PS C:\Users\pjmmc\Documents\Genealogy\Family Tree Files>通过一个消除的过程,我发现[不能在带有Get的路径中使用,而且可能是PowerShell特有的。
我使用的是PowerShell版本5.1。下面的代码是一个测试,以证明违规字符是。我确定这个角色并没有引起任何问题。
PS C:\Users\pjmmc\Documents\Genealogy\Family Tree Files> mkdir "["
PowerShell回答说:
Directory: C:\Users\pjmmc\Documents\Genealogy\Family Tree Files
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 15/06/2022 9:46 PM [PS C:\Users\pjmmc\Documents\Genealogy\Family Tree Files> get-childitem "["
PowerShell回答
Get-ChildItem : Cannot retrieve the dynamic parameters for the cmdlet. The specified wildcard character pattern is not valid: [
At line:1 char:1
+ get-childitem "["
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
+ FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetChildItemCommand 我回到cmd,得到了8.3的名字,一切都很好。也许我可以在Powershell中找到这一点,但对完成任务更感兴趣。
我有几个文件夹的名字。是否有解决办法(作为通配符在获取-儿童项目?)
发布于 2022-06-14 19:09:27
对于这个特殊的案件,试着在下面..。-LiteralPath
Get-ChildItem -LiteralPath "C:\tes[t"
这里有关于这个问题的有趣的GitHub讨论。
[如果'‘存在于路径#12168中。‘,则不能正确解析路径
https://stackoverflow.com/questions/72612814
复制相似问题