Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 30.10.2014 14:58 0 file#1.txt
-a--- 30.10.2014 14:58 0 file#2.txt
PowerShell使用反引号(')作为转义字符,而双引号来评价内容:
Get-ChildItem -Filter "*`#*" -Recurse |
Rename-Item -NewName {$_.name -replace '#','No.' } -Verbose
或
Get-ChildItem -Filter "*$([char]35)*" -Recurse |
Rename-Item -NewName {$_.name -replace "$([char]35)","No." } -Verbose
双方将合作。
Get-ChildItem -Filter "*`#*" -Recurse |
Rename-Item -NewName {$_.name -replace "`#","No." } -Verbose
VERBOSE: Performing the operation "Rename File" on target
"Item: D:\tmp\file#1.txt Destination: D:\tmp\fileNo.1.txt".
VERBOSE: Performing the operation "Rename File" on target
"Item: D:\tmp\file#2.txt Destination: D:\tmp\fileNo.2.txt".
这也将工作,
Get-ChildItem -Filter '*#*' -Recurse |
Rename-Item -NewName {$_.name -replace '#', 'No.'} -Verbose
VERBOSE: Performing the operation "Rename File" on target
"Item: D:\tmp\file#1.txt Destination: D:\tmp\fileNo.1.txt".
VERBOSE: Performing the operation "Rename File" on target
"Item: D:\tmp\file#2.txt Destination: D:\tmp\fileNo.2.txt".
因为PowerShell的解析器是足够聪明,找出你的意图。
如果您在标签或标题中指定工作环境,可能会得到更多答案 – 4rlekin 2014-10-30 08:24:55