簡體   English   中英

無法將 icacls 運行到有空格的目錄

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

我正在嘗試在我的計算機上的目錄中運行一個簡單的 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

正如我所想的那樣,我使用單引號來轉義空格,所以我不知道這里有什么問題。 希望您能夠幫助我。 謝謝!

解決了。 只需要刪除最后一個反斜杠。 干杯。

要為您自己的有效解決方法添加解釋(在您的論點中不包括尾隨\ ):

您所看到的是Windows PowerShell中關於如何將 arguments 傳遞給外部程序的錯誤 - 此問題已Z3D265B4E1EEB10DCCDF1 (7)88810DCCDF1 (核心)

在幕后, PowerShell(必須)將包含空格的引號參數轉換為引號形式,因為只能假定外部 CLI 理解"..."引用。

大多數 CLI 使用的命令行解析規則將序列\"視為轉義"字符,即,將"字符視為參數的逐字部分而不是對其進行定界。

因此,雙引號字符串末尾的逐字\本身必須轉義為\\才能被識別 -這就是 Windows PowerShell 忽略做的事情

也就是說,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\"

icacls.exe解析此命令行時,它會逐字查看.\My Digital Editions" (注意末尾的逐字" ),這反映在錯誤消息中。

相比之下,PowerShell(核心)確實執行了必要的 escaping:

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

作為旁白:

自 7.2.x 起,PowerShell(核心)中仍然存在一個影響"嵌入在 arguments 中如何傳遞給外部程序”的相關錯誤- 請參閱此答案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM