简体   繁体   English

无法将 icacls 运行到有空格的目录

[英]Can't run icacls to a directory with spaces

I'm trying to run a simple icacls to a directory on my computer and I'm facing this error:我正在尝试在我的计算机上的目录中运行一个简单的 icacls,但我遇到了这个错误:


PS C:\Users\gguer\Documents> icacls.exe '.\My Digital Editions\'
.\My Digital Editions": The filename, directory name, or volume label syntax is incorrect.
Successfully processed 0 files; Failed processing 1 files

I'm using single quotes to escape the spaces as I was thought, so I don't know what is the issue here.正如我所想的那样,我使用单引号来转义空格,所以我不知道这里有什么问题。 Hope you can help me.希望您能够帮助我。 Thanks!谢谢!

Solved.解决了。 Just had to remove the last backslash.只需要删除最后一个反斜杠。 Cheers.干杯。

To add an explanation to your own effective workaround (not including a trailing \ in your argument):要为您自己的有效解决方法添加解释(在您的论点中不包括尾随\ ):

What you're seeing is a bug in Windows PowerShell with respect to how it passes arguments to external programs - this problem has been fixed in PowerShell (Core) 7+ .您所看到的是Windows PowerShell中关于如何将 arguments 传递给外部程序的错误 - 此问题已Z3D265B4E1EEB10DCCDF1 (7)88810DCCDF1 (核心)

Behind the scenes, PowerShell (of necessity) translates your single -quoted argument containing spaces to a double -quoted form, because external CLIs can only be assumed to understand "..." quoting.在幕后, PowerShell(必须)将包含空格的引号参数转换为引号形式,因为只能假定外部 CLI 理解"..."引用。

The command-line parsing rules used by most CLIs consider the sequence \" to be an escaped " character, ie a " character to be considered a verbatim part of the argument rather than delimiting it.大多数 CLI 使用的命令行解析规则将序列\"视为转义"字符,即,将"字符视为参数的逐字部分而不是对其进行定界。

Therefore, a verbatim \ at the end of a double-quoted string must itself be escaped as \\ in order to be recognized as such - this is what Windows PowerShell neglects to do :因此,双引号字符串末尾的逐字\本身必须转义为\\才能被识别 -这就是 Windows PowerShell 忽略做的事情

That is, Windows PowerShell translates your call as follows:也就是说,Windows PowerShell 将您的调用翻译如下:

# Resulting command line as used behind the scenes for actual invocation.
# WinPS: BROKEN, because the \ at the end isn't escaped.
icacls.exe ".\My Digital Editions\"

When icacls.exe parses this command line, it sees verbatim .\My Digital Editions" (note the verbatim " at the end), as reflected in the error message.icacls.exe解析此命令行时,它会逐字查看.\My Digital Editions" (注意末尾的逐字" ),这反映在错误消息中。

PowerShell (Core), by contrast, does perform the necessary escaping:相比之下,PowerShell(核心)确实执行了必要的 escaping:

# Resulting command line as used behind the scenes for actual invocation.
# PowerShell (Core): OK
icacls.exe ".\My Digital Editions\\"

As an aside:作为旁白:

A related bug that affects how " embedded in arguments are passed to external programs is still present in PowerShell (Core) as of 7.2.x - see this answer .自 7.2.x 起,PowerShell(核心)中仍然存在一个影响"嵌入在 arguments 中如何传递给外部程序”的相关错误- 请参阅此答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM