在其路径中引用包含方括号 ([]) 的文件 [英] Referencing a file containing square brackets ([]) in it's path
本文介绍了在其路径中引用包含方括号 ([]) 的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 Powershell 的新手,我正在使用 Get-Hash cmdlet:
I'm quite new to Powershell and I'm using the Get-Hash cmdlet:
这有效:
PS M:\> Get-Hash -Path "C:\Users\medmondson\Desktop\New Folder\database.adp" -Algorithm SHA512
这失败了:
PS M:\> Get-Hash -Path "C:\Users\medmondson\Desktop\New [Folder]\database.adp" -Algorithm SHA512
Get-Hash : Cannot bind argument to parameter 'Path' because it is an empty array.
我知道这可能是由于路径 []
中的方括号在 Windows 操作系统下有效.那么我如何让 powershell 摆脱这些?
I understand this is likely due to the square brackets in the path []
which are valid under windows operating systems. So how do I get powershell to escape these?
推荐答案
尝试使用`反引号来转义方括号并将整个字符串用单引号括起来.
Try to use ` backtick to escape the square bracket and enclose the whole string in single quote.
PS M:\> Get-Hash -Path 'C:\Users\medmondson\Desktop\New `[Folder`]\database.adp' -Algorithm SHA512
这篇关于在其路径中引用包含方括号 ([]) 的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文