is there a way rename multiple items in a way that words switch place or move word to the end of the phrase/item name ?
ABCD 12550.txt
into 12550 ABCD.txt
im assuming this will start with Rename-Item
, but what then?
There is a space between words/phrases
CodePudding user response:
Use Rename-Item
with a delay-bind script block, in which you can parse and reconstruct each file name.
The following example uses the -replace
operator to match and capture the base file name's first word as well as the remaining one(s), and reverses their order (effectively moves the first word to the end):
Get-ChildItem *.txt |
Rename-Item -WhatIf -NewName {
($_.BaseName -replace '^(\S ) (. )', '$2 $1') $_.Extension
}
Note: The -WhatIf
common parameter in the command above previews the operation. Remove -WhatIf
once you're sure the operation will do what you want.