Referencing a file containing square brackets ([]) in it's path

给你一囗甜甜゛ 提交于 2019-12-07 08:15:27

问题


I'm quite new to Powershell and I'm using the Get-Hash cmdlet:

This works:

PS M:\> Get-Hash -Path "C:\Users\medmondson\Desktop\New Folder\database.adp" -Algorithm SHA512

This fails:

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.

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?


回答1:


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


来源:https://stackoverflow.com/questions/18660152/referencing-a-file-containing-square-brackets-in-its-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!