Swapping parts of a filename

I have a number of files with the following (sample) file name:

BMRC Committee Meeting Agenda 20210702.docx

I have been trying to create a pattern to change them all to read:

BMRC Committee Meeting 20210702 Agenda.docx

But, I don't seems to be able to create the pattern, please can someone help

Thanks

David
Reply to #1:

Welcome David!

There are a few ways to do this. Regex is a good choice here because of its power and flexibility.

Use a "Replace" method (https://www.advancedrenamer.com/user_guide/method_replace )

And set the the fields as so:

Replace: "(\w+)\s+(\d+)$" (don't include the quotation marks)
Replace with: "$2 $1" (don't include the quotation marks)
Occurrence: All
Case Sensitive: {unchecked}
Use regular expressions: {checked}
Apply To: Name

This assumes that the date is always last and that you are always swapping it with the preceding word.

For an explanation of the above particular regex, see: https://regex101.com/r/Nb2dfk/1/substitution

Regards,
Randy
Reply to #1:

Hi David, Randy,

[Note: I hesitate to add this, since Randy's answer does exactly what you asked, but other readers might get something out of this further discussion.]

Here are a couple more ways to do it. Unfortunately for you, David, they too require regular expressions--although if you do much work with words on a computer you can benefit from some regex knowledge, so it's a blessing AND a curse my friend. If not just pick a method, copy carefully, and get on with your life. :) Oh, and make sure you are using the latest version of Advanced Renamer.

First, and slightly tangentially, if all your filenames are four words and a date as formatted, you can simply:
Use one Replace method WITHOUT regular expressions (as with Randy's answer, don't include the quote marks):
Replace: "<word:4> <word:5>"
With: "<word:5> <word:4>"
Occurrence: All
Case Sensitive: (doesn't matter, nothing is cased in the expressions)
Use regular expressions: {unchecked}
Apply To: Name

That's probably not the case... So this third method at least has something resembling words, so it might be slightly less painful to look at for (someone who I'm assuming is a) first-time regex user. BTW, this will only work if all your dates are eight characters, and if both swap parts have just one space before them and the date has no characters after, so if not you would need to use other methods before to massage the names into compliance. If that's the case let us know.

Use one Replace method (as with Randy's answer, don't include the quote marks):
Replace: "(<rsubstr:10: :1>) (<rsubstr:1:8:1>)"
With: "\2 \1"
Occurrence: All
Case Sensitive: (doesn't matter, nothing is cased in the expressions)
Use regular expressions: {checked}
Apply To: Name

[EDIT: Or, turn off regex and use
Replace: "<rsubstr:10: :1> <rsubstr:1:8:1>"
With: "<rsubstr:1:8:1> <rsubstr:10: :1>" )
Oh dear, now I've made it even worse! :) END EDIT]

(For a description of the <rsubstr> tag, see here: https://www.advancedrenamer.com/user_guide/tags_advanced

The fourth method is similar to Randy's answer... Well, they all are really, but it keys off the spaces around the last two "words" instead of the actual character combinations themselves. There might be times when this is a more useful way to go.

Use one Replace method (as with Randy's answer, don't include the quote marks):
Replace: "([^ ]+) ([^ ]+)$"
With: "\2 \1"
Occurrence: All
Case Sensitive: (doesn't matter, nothing is cased in the expressions)
Use regular expressions: {checked}
Apply To: Name

I'm sure there are other ways to do this, but I just woke up... Cheers, don't worry, it gets better! :)
DF
Reply to #3:

Hello DF,

Your addendum is good, but I note one degradation: Those alternatives don't ensure that one of the words is a date. This could lead to some wonderful chaos. ;P

Regards,
Randy
Reply to #3:

A variation on the last solution that may or may not be more readable, using named references:

Replace: "(?<NextToLastWord>[^ ]+) (?<LastWord>[^ ]+)$"
With: "${LastWord} ${NextToLastWord}"
[everything else the same]

This doesn't change the expressions, just gives them (more) human-readable names. I'm sorry, I can't seem to stop today, my OCD must be flaring... :)

Best,
DF
Reply to #4:
Hi Randy,
Right-ee-o my friend. That's why I talked about pre-massaging if things weren't already in yar ship shape (what, is it talk-like-a-pirate day?)

The same pre-working would be necessary, for instance, if some dates have dashes or periods in them. The space-keyed solution will continue to work. Same for if there are odd characters in the next-to-last word.

That's not degradation, that's logical and realistic alternative! :)

(working on ultimate javascript solution as we type...) LOL j/k

Best,
DF

EDIT: see Addendum thread for a js solution. I guess the "ultimate" part was the only thing I was kidding about!
Reply to #6:
Thank you all for the replies, just wasn't expecting the Spanis Inquisition!

Seriously, I have distant memories of regular expressions from writing awk scripts about a million years ago. The first solution appears to be the one I need, I'll give it a go as soon as I can and I'll report back.

Cheers


David
Reply to #2:

Hi Randy,

It works just fine, thank you

David
Reply to #8:

You're welcome. Cheers!