Subject: Re: [Name Mangler Talk] Moving a section of a file name to a different position

From: Rob Griffiths <[email-masked]>
Date: Tue, 16 Feb 2021 08:57:09 -0800

On Feb 16, 2021, at 6:13 AM, Markus Wernig <[email-masked]> wrote:

> I really appreciate you taking the time to lay it all out for me. I am now beginning to understand how this works. It looks complicated, but it really isn’t, if you know a few basic things (which most of us don’t).

I'n no expert, not even close; I know enough to muddle by, and where to look for answers when I get stuck :). A good regex testing site is a must, as it makes it easy to see how your equation is (or for me, most of the time, is not) working.

> I also found your blog post about all these regex expressions: https://robservatory.com/the-little-i-know-about-regexand-where-to-learn-more/ <https://robservatory.com/the-little-i-know-about-regexand-where-to-learn-more/> Extremely helpful!

Thanks!

> A short tutorial section on the ManyTricks website with some basic explanations and a few real world examples would be awesome for future users. Most of us have no idea that these kinds of text manipulations are even possible.

The challenge with that kind of article is that it's not going to be right for almost anyone, because regex is almost always used on a case-by-case basis. So providing a simple example of moving a date, for instance, would probably only be really helpful for those whose filename patterns match exactly that of the demo.

In the much longer term, we'd like to automate regex in Name Mangler, though I don't know if this will ever come to be, as it's really tricky to do well. Ideally, you'd just select some text, say where you want it to move to, and that'd be that. We'll see—but it's definitely not in the short term future.

> I am already a huge fan of Name Mangler - and honestly - I don’t know how I’d do all my daily file renaming tasks without it. It’s by far the best file renaming app that I have come across. And now that I know how much more we can do with it, I love it even more!

Thanks!

-rob.

---

From: Markus Wernig <[email-masked]>
Date: Tue, 16 Feb 2021 15:13:24 +0100

Thank you so much, Rob!

Thank you so much again!

> On Feb 16, 2021, at 2:25 PM, Rob Griffiths <[email-masked]> wrote:
> 
> On Feb 16, 2021, at 1:42 AM, Markus Wernig <[email-masked] <mailto:[email-masked]>> wrote:
> 
>> But how do I grab just a section of a long file name, and only move that section, let's say to the end of the file name while adding an underscore at the same time?
> 
> The key to grabbing sections is to identify patterns in your filenames. Using the samples you provided....
> 
>> Pulse Layer 5 80 bpm C Sharp.aif
>> Pulse Layer 12 80 bpm B.aif
> 
> ...I'm going to make the safest assumption, which is that your filenames are of this form:
> 
> [some amount of random text] [space] [some number] [space] [bpm] [space] [some amount of random text]
> 
> I'm going to assume the section in bold is the only portion in common among all the files. So my solution needs to capture the first batch of random text as a group, then the number-bpm bit as a group, and then any trailing text as a group. Once captured into groups, rearranging and adding characters is pretty simple. 
> 
> Here's what I came up with:
> 
> Find & Replace, make sure Query is a regular expression is checked.
> 
> Find box: (.*)\ (\d+\ bpm)\ (.*)
> Replace box: $1 $3_$2
> 
> The screenshot shows it in action, doing what you want (I'm pretty sure) to your two sample filenames and a longer meaningless one I made up. Please test first on a backup copy of your files!
> 
> How does it work? Here's the Find bit, broken down:
> 
> (.*) --> on its own, this means "zero or more characters, captured into group $1," and it would capture the entire string, except it stops capturing when...
> 
> \[space](\d+\ bpm) --> ...it encounters a space followed by one or more digits (\d+) followed by a space and the letters bpm. The number[space]bpm bit is captured into group $2
> 
> \[space] --> find the space after the bpm bit, and just drop it (it's not captured into a group, i.e. no parentheses around it)
> 
> (.*) --> find zero or more characters after the last space and capture them into group $3.
> 
> When done, $1 holds all the text before the bpm bit, $2 holds the bpm digits and text, and $3 holds all the trailing text. Rebuilding it is then just a matter of putting it in the order you want, adding back the spaces where needed, and inserting the underscore. So that's just $1 $3_$2
> 
>> Understanding how to achieve this with one Name Mangler task/function would be an amazing time saver!
> 
> Hope that helps; please let me know if you have any questions.
> 
> -rob.
> 
> 
> 
> -- 
> -- 
> You received this message because you are subscribed to the Name Mangler Talk group. To post to this group, send email to [email-masked]. To unsubscribe from this group, send email to [email-masked].
>  
> For more options, visit the Name Mangler Talk web page at <http://groups.google.com/group/name-mangler-talk <http://groups.google.com/group/name-mangler-talk>>
> 
> --- 
> You received this message because you are subscribed to a topic in the Google Groups "Name Mangler Talk" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/name-mangler-talk/K8y9vmxRV2A/unsubscribe <https://groups.google.com/d/topic/name-mangler-talk/K8y9vmxRV2A/unsubscribe>.
> To unsubscribe from this group and all its topics, send an email to [email-masked] <mailto:[email-masked]>.
> To view this discussion on the web visit https://groups.google.com/d/msgid/name-mangler-talk/17ED5EAE-45F4-4118-B712-8E997764FBB3%40manytricks.com <https://groups.google.com/d/msgid/name-mangler-talk/17ED5EAE-45F4-4118-B712-8E997764FBB3%40manytricks.com?utm_medium=email&utm_source=footer>.

---

From: Rob Griffiths <[email-masked]>
Date: Tue, 16 Feb 2021 05:25:42 -0800

-rob.

---

From: Markus Wernig <[email-masked]>
Date: Tue, 16 Feb 2021 01:42:32 -0800 (PST)

>From reading through past conversations I know how I can turn file names 
like W-1.wav into 1-W. That's a simple swap/

But how do I grab just a section of a long file name, and only move that 
section, let's say to the end of the file name while adding an underscore 
at the same time?

Here are two original file name examples (and I have hundreds like this one
Pulse Layer 5 *80 bpm* C Sharp.aif
Pulse Layer 12 *80 bpm* B.aif

They should end up looking like this:
Pulse Layer 5 C Sharp*_80 bpm*.aif
Pulse Layer 12 B*_80 bpm*.aif

Understanding how to achieve this with one Name Mangler task/function would 
be an amazing time saver!