A Thank You • A Request: Trim File Name & Filter Extended Tag

Good day Everyone

Thank you Florian for Mp3tag, and thank you the outstanding regulars who freely contribute your time and skills to assist the basic (read: copy & paste) Mp3tag user like me. I do not post often, but scour the forums regularly and pick up handy tips and scripts along the way, with which to improve my tagging. This forum is a precious source of information, in which your legacy is notable.

That said, after spending a few hours here today looking and reading, I still need to find a specific solution to two tagging needs:

1.] A script/action to trim a file name to any set (fixed) set length (number of characters) from the end of the file name, extension excluded. Example: 64 characters.

2.] A filter for any field in the Extended Tag. Example: Orchestra or Performer.

I have tried several on my own, but although I consult the Help Section regularly, and experiment, I still come adrift.

Could someone please assist me with 1. and 2. above?

Action Type: Format Value
Format string: $left(%_filename%,64)

I am not sure what you mean by this.
You can set a filter for any tag that is embedded in your files. You are not restricted to the tags shown in the tag-panel.

I'm sure you know the basics of how to set these up so I'm not going to bore you with that.

  1. $left(%_filename%,64)
    2a. %Orchestra% PRESENT AND %Performer% PRESENT
    2b. %Orchestra% PRESENT OR %Performer% PRESENT

2a and 2b are self explanatory.

The forum is a great place to learn but you'll never beat the help.


Thank you to all who replied. I appreciate it very much.

Let me go and apply it. :slight_smile:

If I want to set the %_filename% to a fixed number of characters (say again 64), instead of trimming it by 64 characters from the end of the file name- how would it alter this Action supplied by SteveHero? Which Format String to use?

Action Type: Format Value
Format string: $left(%_filename%,64)

100% correct. Personally, I consult the excellent Help files almost daily. Mostly, I help myself by experimenting, but there limits to what I know. It is not at all that Mp3tag lack the powerful program scripts, but rather my understanding of the curt Help-explanations that apply to them. Though some are easy enough to understand, I simply do not know what they mean in others. To students of scripting languages these are usually very obvious. Another factor that may have to be reckoned with, is the language barrier.

This is why I am so very grateful for the forum scripting experts who help us along the way.

If you work with LTR (left to right) languages, then in general trimming means to cut off a part from the right edge of a string.
Mp3tag supports string-functions:


This suggestion from SteveHero and me has the format string to just do what you ask for.

If you really want to set a fixed string, you can alter the suggested format string and use

Action Type: Format Value
Format string: YourFixedStringThatMightBeExactlySixtyFourCharactersLongInTheEnd

If you have a shorter filename and want to add some characters so that it is 64 characters long, try

Format value for _FILENAME
Format string: %_filename%$repeat($sub(64,$len(%filename%)),)

This fills the filename with _ up to the length of 64.
Whatever that may be good for.

Other proposal ...



Thank you all, and sorry about my confusion. I missed the obvious by confusing the trimming of an "x" number of characters from the end of a file string, and setting a fixed number of characters starting from the beginning. I'm getting there though, I and will look at the other methods presented here too.

Let me show you an example of what I find difficult to understand:

Let's say I want to filter (F3) all titles in which the colon (:slight_smile: punctuation mark is present. I'd start with this script, which to me, looks logical:


but the filter does not work. I have tried several variations, without luck. Why is this?

The filter command PRESENT returns all files where the tag field exists.
It is obvious that the colon character is no tag-field.

You have to apply a filter expression like this ...


OK, to my last query, I found this filter to do the trick:

%title% HAS :

Next, I am trying to figure out how to filter those titles in which a colon is present, preceded by the artist, as I would like to remove the artist from those titles.

Filter: "$ifgreater($strstr(%TITLE%,%ARTIST%':'),0,'yes','no')" IS "yes" ... or ... Formatstring for TITLE: $ifgreater($strstr(%TITLE%,%ARTIST%':'),0,$replace(%TITLE%,%ARTIST%':',),%TITLE%)


Thank you DetlevD. I cannot say that I understand it, yet, but I will certainly apply it. :slight_smile:

I stumbled upon this next problem, as I tried to create a file name from tags. Below is one of the strings I apply regularly, but now, where there are too many characters in the title, the file name will exceed the Windows limit. How should I edit my usual string to limit the number of file name characters, created from the title, so the a total Windows path length does not exceed 249 characters?

$replace(%discnumber%-%track%. %title%,/,·, / , · ,:,··,",'',)

Wrap that that whole format string you wrote with the fn I posted at the start.


Then use.


See help for more on validate fn.

Thank you, will do.

How should I maximize the filename.ext to a total character length that will exactly fit into the 249 (current) path limit?

I've edited that post. There was an error in 2nd fn.