通过替换字符和覆盖来重命名文件

Dan*_*iel 3 powershell

在Windows XP上,在文件的文件夹中,我需要重命名一些文件,用另一个文件替换文件名中的一个字符,并覆盖已经具有该名称的任何文件.

例如,该文件夹包含以下两个文件:

fileA.xml
fileb.xml
Run Code Online (Sandbox Code Playgroud)

我需要重命名fileA.xmlfileb.xml,覆盖原fileb.xml

使用PowerShell,我有这个命令:

Get-ChildItem *.* -include *.xml | Rename-Item -NewName { $_.name.Replace("A","b")}
Run Code Online (Sandbox Code Playgroud)

重命名不起作用,因为该文件已存在.

不必在PowerShell中完成,但这是我到目前为止最接近的.

Jos*_*orn 6

您可以Move-Item使用-Force参数尝试命令.

Get-ChildItem . -include *.xml | Move-Item -Destination { $_.name.Replace("A","b")} -Force
Run Code Online (Sandbox Code Playgroud)