转义-LiteralPath
Escape -LiteralPath
我已通过设置将 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
的文件夹。失败:
The string is missing the terminator: '.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : 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 添加到我的上下文菜单中:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\Powershell\command]
@="powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"
这很好用,除了我出色地命名为 Ash's docs
的文件夹。失败:
The string is missing the terminator: '. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : 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\\""