[英]powershell in-place remove double quotes in text file where line starts with double quotes + some other text
[英]writing double quotes to file name text with powershell
我很努力地看到在文件名文本中加雙引號的地方出了錯。 下面的代碼在-whatif傘下可以正常工作,但不能沒有。
$a = "20`" board"
get-childitem | rename-item -newname {$_.fullname -replace "20 board", $a } -whatif
get-childitem | rename-item -newname {$_.fullname -replace "20 board","20`" board" } -whatif
理想的結果是用20" board
代替20 board
。以上代碼片段給我提供了一個rename-item : Illegal characters in path.
。
在Windows中,您不能在文件或文件夾名稱中使用某些字符。 雙引號就是其中之一。
請訪問https://docs.microsoft.com/zh-cn/windows/desktop/fileio/naming-a-file了解更多信息。
該頁面的節選:
The following reserved characters [are not allowed]:
< (less than)
(greater than)
: (colon)
" (double quote)
/ (forward slash)
\ (backslash)
| (vertical bar or pipe)
? (question mark)
* (asterisk)
ArcSet的有用答案包含關鍵指針: "
Windows上的文件和文件夾名稱中不能使用字符。
所需功能有一個-次優- 近似值 :您可以使用外觀上相似的非ASCII雙引號-但請注意,以后需要使用該精確引號來引用該文件(除非您使用通配符來匹配它),因此視覺上的相似性可能導致混淆。
'hi' > "20`“ board" # works, because “ is not a regular double quote
需要注意的是PowerShell將普通雙引號和“
可以互換的,這就是為什么你仍然需要`
-escape “
一個普通的雙引號字符串中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.