Powershell 批量重命名文件中含有 [] 致使報錯

下載的全部文件中都包含了 「[下載網站地址]」, 按照常規方法 ide

Get-ChildItem "D:\Bluey\" -Recurse |ForEach-Object{Rename-Item -Path $_.FullName -NewName $_.FullName.Replace('old','new')}

一直報告沒法發現源文件,查閱後得知當文件名中包含特殊字符,須要使用 -LiteralPath 參數。 網站

Get-ChildItem "D:\Bluey\" -Recurse |
Where-Object {$_.Name -match '\[.+\]' } |
foreach {
    Rename-Item -LiteralPath $_.FullName -NewName $($_.Name -replace '\[.+\]','-')
}

將[]和其間字符替換爲-。 code

相關文章
相關標籤/搜索