Subject: Re: [Name Mangler Talk] Re: Nesting functions and repeated characters

From: Rob Griffiths <[email-masked]>
Date: Thu, 24 May 2012 08:41:07 -0700

On May 23, 2012, at 6:38 PM, Chuck Nicholson wrote:

> Instead of searching for "aaf_", "aab_" and "aa_" and replacing with their corresponding bits, what I'm doing is searching for "aaf", "aab", and "aa"(all without the underscore) then replacing with "aaf.", "aab.", and "aa."

Is this because the underscore isn't really there, and your real filenames are completely different (other than starting with 'aaf,' etc.) than what you send? Can you explain why the simple find using the letters and underscore doesn't work for you? Based on the filenames you sent, it should be perfect.

> Is there a way to get it to only find and replace the prefix instance of "aa" and not the one located in the middle of the "filenaame.ext"?

It is and it isn't. If you just want to find and remove the aa, aaf, and aab, without searching on the underscore, *and* without replacing the underscore, it's a pretty simple regular expression find/replace:

[findRegularExpression
"^aab"
in <name>
replace with "above.all.boards."
]

[findRegularExpression
"^aaf"
in <name>
replace with "all.about.files."
]

[findRegularExpression
"^aa"
in <name>
replace with "ask.again."
]

<name.extension>

Here's how that would rename the sample filenames you provided:

aa_filenaaame.ext  -->  ask.again._filenaaame.ext
aab_filenaame.ext  -->  above.all.boards._filenaame.ext
aaf_filename.ext   -->  all.about.files._filename.ext

The _ is still there because we're not searching on it -- and if we don't search on it, we can't replace it. 

To give you a better answer, I'll need to see some actual filenames (before and after) of what you're facing, instead of the generic example versions. With that, we can probably structure something that does what you need it to do.

regards,
-rob.

---

From: Chuck Nicholson <[email-masked]>
Date: Wed, 23 May 2012 18:38:41 -0700 (PDT)

Hey Rob-

Thanks for the help!

I realize now that I made a mistake in describing the setup, so here's a 
quick addendum:

Instead of searching for "aaf_", "aab_" and "aa_" and replacing with their 
corresponding bits, what I'm doing is searching for "aaf", "aab", and 
"aa"(all without the underscore) then replacing with "aaf.", "aab.", and 
"aa."

This works fine for most cases, except when I have a filename with "aa" in 
it.
It then will turn "aa_filenaame.ext" into "ask.again_filenask.again.me.ext" 
In other words, it's finding the "aa" that is in the rest of the filename 
and replacing it as well as the prefix "aa" that is desired.

Is there a way to get it to only find and replace the prefix instance of 
"aa" and not the one located in the middle of the "filenaame.ext"?

Thanks,
Chuck

On Wednesday, May 23, 2012 11:33:35 AM UTC-4, Chuck Nicholson wrote:
>
> Hi,
>
> I'm trying to rename a set of files that start with multiple common 
> prefixes and different remaining names
> e.g.:
>
> aaf_filename.ext
>> aaf_filename.ext
>> aab_filenaame.ext
>> aab_filenaame.ext
>> aa_filenaaame.ext
>> aa_filenaaame.ext
>
>
> So right now I'm just running a series of "find" functions and replacing 
> the prefixes with their desired replacements.
>
> However, as you can see, the first two letters of each prefix are shared 
> between files, as well as being located in the file names.
>
> I have the droplet set to:
>
> [find "aaf_" <name> "all.about.files."]
>> [find "aab_" <name> "above.all.boards."]
>> [find "aa_" <name> "ask.again."]
>
>
> What happens is, if I keep the functions in the order the files are 
> listed, they rename the prefixes properly but add an "ask.again" to the 
> middle of the "filenaame". 
>
> all.about.files.filename.ext
>> all.about.files.filename.ext
>> above.all.boards.filenask.again.me.ext
>> above.all.boards.filenask.again.me.ext
>> ask.again.filenask.again.ame.ext
>> ask.again.filenask.again.ame.ext
>
>
> If I move the last function to the top, then that gets executed first and 
> the files look like this:
>
> ask.again.f.filename.ext
>> ask.again.f.filename.ext
>> ask.again.b.filenask.again.me.ext
>> ask.again.b.filenask.again.me.ext
>> ask.again.filenask.again.ame.ext
>> ask.again.filenask.again.ame.ext
>
>
> My question is, how do I structure the functions so that the desired parts 
> of each filename get replaced and the undesired parts do not?
>
> Can I nest the "find" functions somehow so that it would only look to 
> replace the "aa" by itself instead of as a part of "aaf" and "aab"?
> Also, how do I get it to ignore the "aa" and "aaa" that is in the middle 
> of the filename that I don't want to touch?
>
> If this is something that regular expressions can handle, awesome, I'll 
> just need to go figure them out. If NM can do this without regex, would 
> someone be able to show me how?
>
> Thanks,
> Chuck
>

On Wednesday, May 23, 2012 11:33:35 AM UTC-4, Chuck Nicholson wrote:
>
> Hi,
>
> I'm trying to rename a set of files that start with multiple common 
> prefixes and different remaining names
> e.g.:
>
> aaf_filename.ext
>> aaf_filename.ext
>> aab_filenaame.ext
>> aab_filenaame.ext
>> aa_filenaaame.ext
>> aa_filenaaame.ext
>
>
> So right now I'm just running a series of "find" functions and replacing 
> the prefixes with their desired replacements.
>
> However, as you can see, the first two letters of each prefix are shared 
> between files, as well as being located in the file names.
>
> I have the droplet set to:
>
> [find "aaf_" <name> "all.about.files."]
>> [find "aab_" <name> "above.all.boards."]
>> [find "aa_" <name> "ask.again."]
>
>
> What happens is, if I keep the functions in the order the files are 
> listed, they rename the prefixes properly but add an "ask.again" to the 
> middle of the "filenaame". 
>
> all.about.files.filename.ext
>> all.about.files.filename.ext
>> above.all.boards.filenask.again.me.ext
>> above.all.boards.filenask.again.me.ext
>> ask.again.filenask.again.ame.ext
>> ask.again.filenask.again.ame.ext
>
>
> If I move the last function to the top, then that gets executed first and 
> the files look like this:
>
> ask.again.f.filename.ext
>> ask.again.f.filename.ext
>> ask.again.b.filenask.again.me.ext
>> ask.again.b.filenask.again.me.ext
>> ask.again.filenask.again.ame.ext
>> ask.again.filenask.again.ame.ext
>
>
> My question is, how do I structure the functions so that the desired parts 
> of each filename get replaced and the undesired parts do not?
>
> Can I nest the "find" functions somehow so that it would only look to 
> replace the "aa" by itself instead of as a part of "aaf" and "aab"?
> Also, how do I get it to ignore the "aa" and "aaa" that is in the middle 
> of the filename that I don't want to touch?
>
> If this is something that regular expressions can handle, awesome, I'll 
> just need to go figure them out. If NM can do this without regex, would 
> someone be able to show me how?
>
> Thanks,
> Chuck
>

---

From: Rob Griffiths <[email-masked]>
Date: Wed, 23 May 2012 09:40:50 -0700

> aa_filenaaame.ext

You show six files there, but each one has a dupe, so I'm assuming you meant to just give three examples, right?

> My question is, how do I structure the functions so that the desired parts of each filename get replaced and the undesired parts do not?

If you use Advanced mode, you can do this in one droplet, and without touching any regex. Here's the code:

[find
	"aa_"
	in <name>
	
[find
	"aab_"
	in <name>
	
[find
	"aaf_"
	in <name>

<name.extension>

And a screenshot of it in action, using your three sample filenames, is (hopefully) attached below. Note that you should experiment on copies of your files (or even better, on dummy text files named the same way) to make sure there aren't any glitches when using actual filenames.

Before using for real, please have a backup copy of your files, just in case.

regards,
-rob.

----------

---

From: Chuck Nicholson <[email-masked]>
Date: Wed, 23 May 2012 08:33:35 -0700 (PDT)

Hi,

aaf_filename.ext

> [find "aa_" <name> "ask.again."]

What happens is, if I keep the functions in the order the files are listed, 
they rename the prefixes properly but add an "ask.again" to the middle of 
the "filenaame". 

ask.again.f.filename.ext

Can I nest the "find" functions somehow so that it would only look to 
replace the "aa" by itself instead of as a part of "aaf" and "aab"?
Also, how do I get it to ignore the "aa" and "aaa" that is in the middle of 
the filename that I don't want to touch?

Thanks,
Chuck