Action to import the content of a txt file


After searching I found that the latest development build has an action
for what sounds like the thing I'm after, but I don't know how to make it work.
I want to import the content of the text file into my Comments tag, there's usually
one .TXT file only in the folder I'm working with. It is usually named info.text or
Is there an easy way to do this? I think there is...


I think not. Mp3tag needs to know the name of the text file.


Hi - thanks.
OK, maybe I can make three different actions that will cover
most of these. Say the the file is named info.txt, how can i
make an action to import the text into my Comments tag?



Well ..., you can make an action to import the text into your Comments tag in the same way as you can work with all the other Mp3tag actions (hint: see helpfile, search this forum).

General method:
Choose the right action (hint: you want to import a text file), fill in the proper values into the action form dialog (hint: your filename is 'info.txt' and you want to import the data into the comments tagfield).
Run the action against the trackfiles you want to change.

Good luck!



Thank you for taking your time to answer me at length and especially for
providing me with the hints, very useful and I will go back to where I started
and search the forum and help file again, since I couldn't find it and couldn't
get it to work the first time. But now, with your help, I will probably find out.


I have now gone back to the Help file and searched the forum again.

The Help file didn't provide me with any info about importing a .txt file,
and neither did a search of the forum. But in the action dialogue is a preformatted
action "import from text file". All references to this new action (in the latest
development build) that I find here in the forum is more or less directed to people
who already have a detailed understanding of how it works.

Please, how do I use the different alternatives:


Seems like this is already prepared for to make it simple and easy, I just need
the description of how to go ahead.

Thanks in advance


I think you do not need any of the above listed 'different alternatives' to use 'action import' in it's normal standard simple basically mode.

You have to input only two values.

  1. The name of the tagfield you want to be filled with the data from your textfile.
  2. The filepath to the storage place of your textfile.
    The action dialog has no built in filesystem search dialog, therefore you have to type in manually the filepath or you can use copy&paste functionality by copying the proper filepath from anywhere else and pasting it into the editfield.

The german help file says:
Text-Dateien importieren
Mit dieser Aktion können Sie Inhalte einer Text-Datei in Tag-Felder übernehmen.
Als Formatstring für den Dateinamen können Sie neben einem festen Dateinamen auch Platzhalter verwenden.
Um zum Beispiel den Inhalt der Datei lyrics.txt in das Feld 'UNSYNCEDLYRICS' zu importieren, geben Sie als Feldname UNSYNCEDLYRICS und als Formatstring lyrics.txt an.

My approach of translation:
Import text files
With this action you can put data from an external text file into a tagfield.
As a format string for the filename you can use a given filepath and also use Mp3tag placeholders and scripting functions.
For example, to import the content of the file 'lyrics.txt' into the tag field 'UNSYNCEDLYRICS', enter as a field name "UNSYNCEDLYRICS" and as a format string "lyrics.txt" (without the double quotes).
Make sure that the file can be found and read from the given resp. calculated filepath.



THANKS, this fixed a lot of my text files!

I have a follow up questions since I will now import and tag a large number of files,
they are all in folders named

This is also the way that each file is named, but
inserting "t01" etc before the "flac" at the end.

The text file is also named like this, but with .txt at the end.

My question:
I import all the folders in to the MP3tag screen and would like to
use an action to import the text file in to the Comments field...



Hmm ..., now it looks rather simple:
Get the folder name (%directory%),
replace ".flac" by ".txt" ($replace(%directory%,.flac,.txt)),
use this as a format string and
use COMMENT as a field name in the action dialog (as described in previous post).



Thanks DetlevD, this made me understand, I can use this formula
for other things as well.

Seems like there are cases where I need to delete one part of
the folder name, to get the text file name.
Say that "band" has to be deleted as well as changing the flac to txt in

Can I do that in the same action - I tried but couldn't work it out.
How do I delete that part of the folder name?


You use filenames which are built from a bunch of items which are structured in the first level by a point and in the second level by a hyphen. Each item can have constant and/or varying content.

  • item 1: artistyear-month-day
    • item 1.1: artistyear
    • -
    • item 1.2: month
    • -
    • item 1.3: day
  • .
  • item 2: source
  • .
  • item 3: band
  • .
  • item 4: 't'01 (character constant with appended varying tracknumber)
  • .
  • item 5: 'flac' (string constant)
The filename including filename extension %_filename_ext% resp. _FILENAME can be read as a list of five items delimited by a point character.
To delete a specific item from the list you have to know resp. to find it's position and remove it.

How to do this with the Mp3tag toolbox without having such list oriented functions?

Hmm ..., it seems $regexp() function can help to solve the problem.

As a regular expression your %_filename_ext% resp. _FILENAME looks like:

Each content of an item from within a pair of rounded brackets can be used for replacement by an indicated placeholder, e. g. $1 stands for the first item from the left, $2 for the second item and so on.
So the unaltered content of %_filename_ext% resp. _FILENAME can be rebuild by this replacement expression:
$1.$2.$3.$4.$5 gives

To delete the third item simply remove the placeholder $3:
$1.$2.$4.$5 gives artistyear-month-day.source.t01.flac

You can create following action to delete the third item from a filename of the given format:

Action #1:
Action type: Replace with regular expression
Regular expression: (.?).(.?).(.?).(.?).(flac)
Replace matches with: $1.$2.$4.$5

[ ] case-sensitive comparison



Detlev, here *V2.39f) that fails to change I can't see why. But

Regular expression: (.?).(.?).(.?).(.?)(flac)

succeeds. Puzzling.

Also, here's a more concise (though less educational) solution:

Regular expression: (....).*.(flac)
Replace matches with: $1$2


Chris, be aware that I've edit my first post and added one more item to the filename!
Please check it again.



Ah yes, that's what cought me out! Thanks.


This is great, very useable, and I am learning
a little (not all though...) on the way.
Thanks for your help


One more question... :unsure:

This works for me but I can't understand how to
find a workaround for doing this:

  • the folder where my files are is named:

  • the text file I am importing to my Comment field is named:
    "artistyear-month-day.source.txt" (band is deleted)

How do write my txt import formula to make this import?

Thanks in advance

Best wishes


Hmm ..., to combine what you have learned in Post#9 and Post #11:

file: artistyear-month-day.source.txt


Import from Textfile



Edit: Changed spelling mistake from "%DIRECTORY%" to "%_DIRECTORY%".
Edit: Added colors for better visual realization.

QUOTE (DetlevD @ Dec 9 2007, 12:00) <{POST_SNAPBACK}>
Hmm ..., to combine what you have learned in Post#9 and Post #11:
Action  : Import from Textfile
Field   : COMMENT
Filename: $regexp(%DIRECTORY%,^(.*?)\.(.*?)\.(.*?)\.(.*?)$,$1.$2.txt)


Thanks...I don't really understand (sort of like before) but this time
I can't get it to work... make me understand - how would this formula look if I were to
delete the "source" part in the folder name instead, to get the txt file name right?
I can't really see the way the different parts of the file name is built up.

is this correct...?


I think I am doing something wrong.



See my altered previous post and try again.

Yes, regardless of my spelling mistake on the system placeholder "%_DIRECTORY%".



Import from Textfile





Thank you, everything worked like a charm!
I really appreciate your help
Best wishes