Rename file by replacing character and overwrite

后端 未结 2 1361
醉酒成梦
醉酒成梦 2021-01-20 02:08

On Windows XP, in a folder of files, I need to rename some files, replacing one character in the filename with another and overwriting any files that already have that name.

相关标签:
2条回答
  • 2021-01-20 02:50

    You can try the Move-Item command instead, with the -Force parameter.

    Get-ChildItem . -include *.xml | Move-Item -Destination { $_.name.Replace("A","b")} -Force
    
    0 讨论(0)
  • 2021-01-20 02:53

    First, you need to filter to get the files that you actually want to rename.

    Get-ChildItem . -include *.xml | Where-Object { $_.name -match "A$" }
    

    And feed this to Move-Item to rename:

    Get-ChildItem . -include *.xml | Where-Object { $_.name -match "A$" } | Move-Item -destination { $_.name -replace "A$", "b" }
    
    0 讨论(0)
提交回复
热议问题