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

相关文章
相关标签/搜索