# Action to import the content of a txt file

**URL:** https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798
**Category:** Support
**Created:** [November 26, 2007, 7:18pm UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798 "2007-11-26T19:18:42Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![HankD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/hankd/32/5130_2.png) [@HankD](https://community.mp3tag.de/u/HankD)
#### Post date: [November 26, 2007, 7:18pm UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/1 "2007-11-26T19:18:42Z")

</div>

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  
foldername.txt...  
Is there an easy way to do this? I think there is...  
Best  
---Hank

---

<div class="post-metadata">

### Author: ![chrisjj](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@chrisjj](https://community.mp3tag.de/u/chrisjj)
#### Post date: [November 26, 2007, 7:39pm UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/2 "2007-11-26T19:39:41Z")

</div>

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

---

<div class="post-metadata">

### Author: ![HankD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/hankd/32/5130_2.png) [@HankD](https://community.mp3tag.de/u/HankD)
#### Post date: [November 28, 2007, 10:19am UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/3 "2007-11-28T10:19:12Z")

</div>

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?

Best  
---Hank

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [November 28, 2007, 11:33am UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/4 "2007-11-28T11:33:17Z")

</div>

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!

DD.20071128.1334

---

<div class="post-metadata">

### Author: ![HankD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/hankd/32/5130_2.png) [@HankD](https://community.mp3tag.de/u/HankD)
#### Post date: [November 28, 2007, 12:04pm UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/5 "2007-11-28T12:04:07Z")

</div>

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.  
---Hank

---

<div class="post-metadata">

### Author: ![HankD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/hankd/32/5130_2.png) [@HankD](https://community.mp3tag.de/u/HankD)
#### Post date: [November 28, 2007, 12:36pm UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/6 "2007-11-28T12:36:47Z")

</div>

> [@HankD](#):
>
> 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.  
> ---Hank

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:

%\_extension%  
%\_filename%.txt  
%filetype%=TXT  
%origfilename%

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  
---Hank

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [November 28, 2007, 2:24pm UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/7 "2007-11-28T14:24:21Z")

</div>

> [@HankD](#):
>
> 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:  
> %\_extension%  
> %\_filename%.txt  
> %filetype%=TXT  
> %origfilename%  
> 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 ---Hank

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.

DD.20071128.1624

---

<div class="post-metadata">

### Author: ![HankD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/hankd/32/5130_2.png) [@HankD](https://community.mp3tag.de/u/HankD)
#### Post date: [December 3, 2007, 2:38pm UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/8 "2007-12-03T14:38:24Z")

</div>

> [@DetlevD](#):
>
> 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 wildcards or 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 filepath.
> 
> DD.20071128.1624

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

artistyear-month-day.source.band.flac

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.  
artistyear-month-day.source.band.txt

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...

Thanks  
---Hank

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [December 3, 2007, 4:24pm UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/9 "2007-12-03T16:24:39Z")

</div>

> [@HankD](#):
>
> 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  
> artistyear-month-day.source.band.flac  
> 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.  
> artistyear-month-day.source.band.txt  
> 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...  
> Thanks ---Hank

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).

DD.20071203.1824.CET

---

<div class="post-metadata">

### Author: ![HankD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/hankd/32/5130_2.png) [@HankD](https://community.mp3tag.de/u/HankD)
#### Post date: [December 3, 2007, 5:34pm UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/10 "2007-12-03T17:34:06Z")

</div>

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  
artistyear-month-day.source.band.flac

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?  
THANKS

> [@DetlevD](#):
>
> 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).
> 
> DD.20071203.1824.CET

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [December 5, 2007, 10:30am UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/11 "2007-12-05T10:30:30Z")

</div>

> [@HankD](#):
>
> 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  
> artistyear-month-day.source.band.flac  
> 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? THANKS

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.

artistyear-month-day.source.band.t01.flac

- 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:  
**(._?__).(._?).(._?__).(._?).(flac)**

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 **artistyear-month-day.source.band.t01.flac**

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**  
_Field:_ **\_FILENAME**  
_Regular expression:_ **(._?).(._?).(._?).(._?).(flac)**  
_Replace matches with:_ **$1.$2.$4.$5**

[] case-sensitive comparison

DD.20071205.1230

---

<div class="post-metadata">

### Author: ![chrisjj](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@chrisjj](https://community.mp3tag.de/u/chrisjj)
#### Post date: [December 5, 2007, 10:42pm UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/12 "2007-12-05T22:42:00Z")

</div>

> [@DetlevD](#):
>
> 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**  
> _Field:_ **\_FILENAME**  
> _Regular expression:_ **(._?).(._?).(._?).(._?).(flac)**  
> _Replace matches with:_ **$1.$2.$4.$5**

Detlev, here \*V2.39f) that fails to change **artistyear-month-day.source.band.flac**. 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**

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [December 5, 2007, 11:47pm UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/13 "2007-12-05T23:47:23Z")

</div>

> [@chrisjj](#):
>
> Detlev, here \*V2.39f) that fails to change **artistyear-month-day.source.band.flac**. I can't see why. ...

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

DD.20071206.0148.CET

---

<div class="post-metadata">

### Author: ![chrisjj](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@chrisjj](https://community.mp3tag.de/u/chrisjj)
#### Post date: [December 5, 2007, 11:58pm UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/14 "2007-12-05T23:58:41Z")

</div>

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

---

<div class="post-metadata">

### Author: ![HankD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/hankd/32/5130_2.png) [@HankD](https://community.mp3tag.de/u/HankD)
#### Post date: [December 8, 2007, 9:21am UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/15 "2007-12-08T09:21:36Z")

</div>

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

---

<div class="post-metadata">

### Author: ![HankD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/hankd/32/5130_2.png) [@HankD](https://community.mp3tag.de/u/HankD)
#### Post date: [December 9, 2007, 8:54am UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/16 "2007-12-09T08:54:15Z")

</div>

One more question... ![:unsure:](https://community.mp3tag.de/uploads/default/original/1X/cfaeba84fe6704387c5b34dfdd8172bd51b6f533.gif ":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:  
"artistyear-month-day.source.band.flac"

- 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  
---Hank

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [December 9, 2007, 10:00am UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/17 "2007-12-09T10:00:05Z")

</div>

> [@HankD](#):
>
> ...
> 
> - the folder where my files are is named:  
> "artistyear-month-day.source.band.flac"
> - 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? ...

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

folder: **artistyear-month-day.source.band.flac**  
file: **artistyear-month-day.source.txt**

Action:

Import from Textfile

 

Field:  
**COMMENT**

 

Filename:  
**$regexp(%\_DIRECTORY%,^(._?__).(._?).(._?__).(._?)$,$1.$2.txt)**

 

DD.20071209.1200.CET  
Edit: Changed spelling mistake from "%DIRECTORY%" to "%\_DIRECTORY%".  
Edit: Added colors for better visual realization.  
DD.200712091403.CET

---

<div class="post-metadata">

### Author: ![HankD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/hankd/32/5130_2.png) [@HankD](https://community.mp3tag.de/u/HankD)
#### Post date: [December 9, 2007, 10:43am UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/18 "2007-12-09T10:43:14Z")

</div>

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)

```

DD.20071209.1200.CET

Thanks...I don't really understand (sort of like before) but this time  
I can't get it to work...

Hmmm...to 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...?

$regexp(%DIRECTORY%,^(._?).(._?).(._?).(._?)$,$1.$3.txt)

I think I am doing something wrong.

Cheers  
---H

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [December 9, 2007, 12:19pm UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/19 "2007-12-09T12:19:19Z")

</div>

> [@HankD](#):
>
> Thanks...I don't really understand (sort of like before) but this time  
> I can't get it to work...

See my altered previous post and try again.

> [@HankD](#):
>
> Hmmm...to 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...?  
> $regexp(%DIRECTORY%,^(._?).(._?).(._?).(._?)$,$1.$3.txt) ...

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

folder: **artistyear-month-day.source.band.flac**  
file: **artistyear-month-day.band.txt**

Action:

**Import from Textfile**

 

Field:  
**COMMENT**

 

Filename:  
**$regexp(%\_DIRECTORY%,^(._?__).(._?).(._?__).(._?)$,$1.$3.txt)**

 

DD.20071209.1420

---

<div class="post-metadata">

### Author: ![HankD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/hankd/32/5130_2.png) [@HankD](https://community.mp3tag.de/u/HankD)
#### Post date: [December 9, 2007, 9:36pm UTC](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798/20 "2007-12-09T21:36:04Z")

</div>

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

[Next page](https://community.mp3tag.de/t/action-to-import-the-content-of-a-txt-file/5798.md?page=2)
