gpt4 book ai didi

powershell - 转义 -LiteralPath

转载 作者:行者123 更新时间:2023-12-02 23:07:42 28 4
gpt4 key购买 nike

我通过设置将 PowerShell 添加到我的上下文菜单中:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\Powershell\command]
@="powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"

这很好用,除了我巧妙地命名为 Ash's docs 的文件夹。 .哪个失败了:

该字符串缺少终止符:'。
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullQualifiedErrorId : TerminatorExpectedAtEndOfString

来自 Set-Location 文档:

Specifies a path of the location. The value of the LiteralPath parameter is used exactly as it is typed. No characters are interpreted as wildcard characters. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell PowerShell not to interpret any characters as escape sequences.



我可以选择在这里使用 -Path并希望我的目录中没有可能包含通配符的目录?或者可以转义 %V中的单引号吗? ?

最佳答案

将路径放在双引号中而不是单引号中。双引号不能出现在路径中。但是,双引号必须转义两次:对于 .reg 文件和 PowerShell 调用。

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\Powershell\command]
@="powershell.exe -NoExit -Command Set-Location -LiteralPath \\\"%V\\\""


关于powershell - 转义 -LiteralPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57372967/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com