Rename file by replacing character and overwrite

后端 未结 2 1362
醉酒成梦
醉酒成梦 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: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" }
    

提交回复
热议问题