Script Query: Extracting Text Inside Square Brackets, From Directory Name

I'm a long-time fan of MP3Tag,
but recently, I've been unlocking more of the power of MP3Tag :slight_smile:

My query:

I have many folders, e.g.

James - Album1-[LMNOP123]-2019

Is there a script function, to extract the text within the square brackets "[" and "]" of a folder,
and write this text into the tag ?

LMNOP123 -> written into 'Comments' field
XYZ3210 -> written like this " XYZ3210 - %publisher% " (into 'Comments field' )

I'm just having issues, trying to 'select' text, inside square-brackets
and most functions are for trim/cut only or the other functions, rely on specifying the 'n' (number) of characters, but as you can see the folder names all have varying length, some with spaces, some with underscores but all with text inside the square brackets.

Try Convert>Filename-Tag
Format string: %dummy%[%comment%]%dummy%\%dummy%

1 Like

wow....ohrenkino , your solution and it works!
in fact, it's 'too simple', that i should have thought of that :thinking:

it's basically, what i was after!

Now, out of curiousity, is it possible to grab certain part of the folder,
e.g. Smith_-_Album_2-[ XYZ3210 ]-2017

and then inserting that, as part of another tag,
XYZ3210 -> written like this " XYZ3210 - %publisher% " (into 'Comments field' )
XYZ3210 --> written like this " XYZ Productions -- XYZ3210 " (into 'Publisher field')

Basically, if there's something in 'Publisher' already,
then XYZ3210 is the catalog number, within that Publisher or Record Label,
as if the text in the square-brackets is a suffix to whatever already inside Publisher.

I don't know if there's a "Catalog" ID3 tag, but this is just my way of grabbing catalog-numbers into ID3 tags.

There are, of course, several ways that may lead to the desired outcome.
There is a 1-step-way with an action of the type "Guess value"
Source pattern: $regexp(%_directory%,'.*\[(.*)\].*',$1) - %publisher%
Target string: %comment%
or, if the target is publisher:
Source pattern: %publisher% - $regexp(%_directory%,'.*\[(.*)\].*',$1)
Target string: %publisher%

Or you import the catalog no. into a user-defined field (e.g. MY_CATNO) with the convert-function,
then add the content of MY_CATNO to the repective field with an action of the type "Format value" e.g.
Format value for PUBLISHER:
Format string: %publisher% - %MY_CATNO%
and after that you can delete MY_CATNO

1 Like

That's exactly what I was looking for.
You've saved me (again) !

I didn't understand the "Guess Value" action,
until the way you showed it to me.

Your solution is simple & elegant.
I can build upon that now :slight_smile: