Swap strings before & after hyphen in file name

I frequently need to rename files by swapping the text before and after the hyphen in file names. I'm sure there must be an easy way to do this but I can't work it out.

For example, I want to change the original file name:

Stevie Wonder - I Wish.pdf

to

I Wish - Stevie Wonder.pdf

Thank you in advance for your help!

This code works for me but I am no expert in Regular Expressions (yet :slight_smile:) so you'll probably get a better solution from someone else.

Rename PATTERN="(.*) - (.*)" TO="\2 - \1" REGEXP IGNOREEXT 
1 Like

I do a similar thing all the time but in my case I rearrange three elements such as:

20190515 - SBS ONE HD - Eurovision Song Contest.ts
to
Eurovision Song Contest - SBS ONE HD - 20190515.ts

Using Regular Expressions
Old Name: (.*) - (.*) - (.*).ts
New Name: \3 - \2 - \1.ts

1 Like

Thank you, blueroly! Works perfectly.

And bhutch, I'll definitely be able to use this one too.

1 Like