# Please add ability to use functions in "Filename to Tag" and "Textfile to Tag"

**URL:** https://community.mp3tag.de/t/please-add-ability-to-use-functions-in-filename-to-tag-and-textfile-to-tag/64920
**Category:** General Discussion
**Created:** [June 1, 2024, 7:47pm UTC](https://community.mp3tag.de/t/please-add-ability-to-use-functions-in-filename-to-tag-and-textfile-to-tag/64920 "2024-06-01T19:47:15Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![FaceCrap](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/f/b5ac83/32.png) [@FaceCrap](https://community.mp3tag.de/u/FaceCrap)
#### Post date: [June 1, 2024, 7:47pm UTC](https://community.mp3tag.de/t/please-add-ability-to-use-functions-in-filename-to-tag-and-textfile-to-tag/64920/1 "2024-06-01T19:47:15Z")

</div>

I would be a very happy user if the use of functions could be added to the "Filename to Tag" convert option.

I'm not sure if "Text File to Tag" could benefit from the same, but since we already have the option in "Tag to Tag" and "Tag to Filename", why not.

Reasoning is my recent post about how to drop the leading zero from tracknumbers when reading the info from a filename. The offered solution by [ohrenkino](https://community.mp3tag.de/u/ohrenkino) works, but boy is it convoluted. And I just spent half an hour trying to get the same kind of action working for a different format (I am absolutely not comfortable with RegExp and Guessing Values, so there's that too)

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [June 1, 2024, 8:09pm UTC](https://community.mp3tag.de/t/please-add-ability-to-use-functions-in-filename-to-tag-and-textfile-to-tag/64920/2 "2024-06-01T20:09:16Z")

</div>

Just a little philosophy:  
Functions work on a given string - so you would have to supply the whole string for a function.  
When you use the converter Filename-Tag for something like  
01 - Abba - Waterloo  
with the matching format string like  
%track% - %artist% - %title%  
but you want to strip the leading zero with  
$num(%track%,1)  
then %track% does not contain any data at that time as TRACK has to be filled first - and that is what you do, when you assign the pattern in Convert\>Filename - Tag.  
The same applies to Convert\>Textfile - Tag.  
See the documentation on the difference between matching and generating format strings:

> **[Format Strings and Placeholders – Mp3tag Documentation](https://docs.mp3tag.de/format/)**
>
> Documentation on format strings and placeholders to describe the structure of file names and imported data. Mp3tag is the universal Tag Editor.

And in that respect

> [@FaceCrap](#):
>
> "Tag to Tag" and "Tag to Filename"

ask for generating format strings and not matching format strings.  
So I would think that the current behaviour is by design.

---

<div class="post-metadata">

### Author: ![FaceCrap](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/f/b5ac83/32.png) [@FaceCrap](https://community.mp3tag.de/u/FaceCrap)
#### Post date: [June 2, 2024, 3:06pm UTC](https://community.mp3tag.de/t/please-add-ability-to-use-functions-in-filename-to-tag-and-textfile-to-tag/64920/3 "2024-06-02T15:06:16Z")

</div>

Honestly I don't see the problem, your argument that TRACK has to be filled first doesn't hold water.  
MP3Tag reads the value from disk, and can then execute the function on said value... if needed after storing that value in TRACK.

---

<div class="post-metadata">

### Author: ![Doug\_Mackie](https://community.mp3tag.de/user_avatar/community.mp3tag.de/doug_mackie/32/279_2.png) [@Doug\_Mackie](https://community.mp3tag.de/u/Doug_Mackie)
#### Post date: [June 2, 2024, 3:09pm UTC](https://community.mp3tag.de/t/please-add-ability-to-use-functions-in-filename-to-tag-and-textfile-to-tag/64920/4 "2024-06-02T15:09:27Z")

</div>

> [@FaceCrap](#):
>
> ...I am absolutely not comfortable with RegExp and Guessing Values...

OK, here is a way to avoid RegExp and functions when a group of file names have consecutive track numbers in an unwanted format:

1. **Sort** the files as you want them to be numbered and select the group.

2. Do your standard **Filename to Tag** conversion using the existing tags.

3. Use the **Auto-numbering Wizard** to replace the unwanted Track tag format with the number format you want.

4. Run **Tag to Filename** to add the new tag numbers (and your other tags) to the file names.

Four steps but no functions or RegExp. Obviously, this technique only works when the target file tracks are numbered consecutively.

I used this method in my earliest days with Mp3tag when I had no skills with functions or with RegExP.

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [June 2, 2024, 3:28pm UTC](https://community.mp3tag.de/t/please-add-ability-to-use-functions-in-filename-to-tag-and-textfile-to-tag/64920/5 "2024-06-02T15:28:28Z")

</div>

> [@FaceCrap](#):
>
> Honestly I don't see the problem

I can't do anything against that you don't see the problem. Just don't be surprised that a function that needs a string to function does not work if there is no string.

Your description

> [@FaceCrap](#):
>
> if needed after storing that value in TRACK.

is absolutely correct: you have to store the value first and then you can execute more or less every action/manipulation on it.  
But you said already

> [@Filename \> Tag: Drop leading zero on tracknumber](https://community.mp3tag.de/t/filename-tag-drop-leading-zero-on-tracknumber/64861/1):
>
> And I hate having to do two actions for one thing.

The already working method is to use the admittedly in this case more complex action "Guess value"  
"Guess value" takes more or less any string and not just the filename for convenience reasons and then allows to prepare that string so that the bits and pieces can be assigned to (other) fields.

So, the only method for the time being, until your feature request is implemented is either go the way with several steps with the existing Convert\>Filename-Tag and then further actions or fewer steps with an action of the type "Guess value".which requires a more complex preparation.
