# Export M3U script to ignore sub folders

**URL:** https://community.mp3tag.de/t/export-m3u-script-to-ignore-sub-folders/47955
**Category:** Support
**Created:** [February 23, 2020, 8:50am UTC](https://community.mp3tag.de/t/export-m3u-script-to-ignore-sub-folders/47955 "2020-02-23T08:50:54Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![RussianMix](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/cc9497/32.png) [@RussianMix](https://community.mp3tag.de/u/RussianMix)
#### Post date: [February 23, 2020, 8:50am UTC](https://community.mp3tag.de/t/export-m3u-script-to-ignore-sub-folders/47955/1 "2020-02-23T08:50:54Z")

</div>

I have 500 folders i need to batch create M3U file for each **folder** (album), currently i use export script that looks like this

```
$filename(m3u,ansi)#EXTM3U
$loop(%_filename_ext%)#EXTINF:%_length_seconds%,%artist% - %title%
%_path%
$loopend()

```

It works great, however if **folder** (Album) has sub folders **CD1, CD2, CD3** it creates three M3U files for each sub folder

```
MyMusic\Album\CD1 
MyMusic\Album\CD2 
MyMusic\Album\CD3

```

Need to modify export script to create **single M3U file** for whole **Album** that will point to mp3 files inside sub folders (CD1, CD2, CD3) and **NOT** 3 separate M3U files for each folder.

---

<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: [February 23, 2020, 9:01am UTC](https://community.mp3tag.de/t/export-m3u-script-to-ignore-sub-folders/47955/2 "2020-02-23T09:01:54Z")

</div>

The easiest way would be to use the function File\>Create Playlist (for selected files).  
This will save the playlist in the current working directory.  
Or see e.g. here:

> [@Create Batch Playlists Placed in Individual Folders](https://community.mp3tag.de/t/create-batch-playlists-placed-in-individual-folders/11405):
>
> Hello, I would like to know if there is a way to create playlists in batch mode and have the playlists placed in the individual album folders? I separate my music in folders by genre, artist and album, for example Blues\B B King\Album1 Blues\B B King\Album2 etc. Rather than load ever album in MP3 Tag and create a playlist one at a time I would like to load the Blues folder and create a separate playlist for every album and have it placed on let's say Album1, Album2, etc. I will greatly ap…

---

<div class="post-metadata">

### Author: ![RussianMix](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/cc9497/32.png) [@RussianMix](https://community.mp3tag.de/u/RussianMix)
#### Post date: [February 23, 2020, 9:09am UTC](https://community.mp3tag.de/t/export-m3u-script-to-ignore-sub-folders/47955/3 "2020-02-23T09:09:11Z")

</div>

> [@ohrenkino](#):
>
> The easiest way would be to use the function File\>Create Playlist (for selected files).  
> This will save the playlist in the current working directory.  
> Or see e.g. here:

This does not solve my main problem, it still creates separate playlists for each individual sub folder within album.

---

<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: [February 23, 2020, 9:19am UTC](https://community.mp3tag.de/t/export-m3u-script-to-ignore-sub-folders/47955/4 "2020-02-23T09:19:49Z")

</div>

I just loaded the folder "Music" with several subfolders "Album1", "Album2" etc.  
Now "Music" is the working folder.  
I selected files from 2 subfolders and called the function File\>Playlist (for selected files).  
The resulting, single playlist looks like this:  
`#EXTM3U`  
`#EXTINF:552,Babel - Jerry Sprunger - Lemi Vice & Action Jackson Remix (Dirty)`  
`Ambient Diary.One - 1997\ambient Diary.One _ 001 _ Babel _ The Return - of Babel''.mp3`  
...  
`#EXTINF:309,Index ID - Federflug`  
`Ambient Diary.Three - 2000\Ambient Diary.Three _ 105 _ Index ID _ Federflug.mp3`  
...

---

<div class="post-metadata">

### Author: ![RussianMix](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/cc9497/32.png) [@RussianMix](https://community.mp3tag.de/u/RussianMix)
#### Post date: [February 23, 2020, 9:27am UTC](https://community.mp3tag.de/t/export-m3u-script-to-ignore-sub-folders/47955/5 "2020-02-23T09:27:28Z")

</div>

> [@ohrenkino](#):
>
> I just loaded the folder "Music" with several subfolders "Album1", "Album2" etc.  
> Now "Music" is the working folder.  
> I selected files from 2 subfolders and called the function File\>Playlist (for selected files).

Here is the result of `Ctrl + Shft + P` that as description say `Playlist (all files) with one playlist for each subfolder`

Here is example of Album that has sub folders (total 500 loaded in Mp3Tag)  
 ![1](https://community.mp3tag.de/uploads/default/original/2X/f/fd36f9c05a533316f003c26271c19fb014b58adf.jpeg)

It creates playlist for each sub folder of album.  
 ![2](https://community.mp3tag.de/uploads/default/original/2X/0/0c131555e9d7276b6aa10822f5f7ca855d69861f.jpeg)

I need one M3U file for each sub folder of Album.

---

<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: [February 23, 2020, 9:29am UTC](https://community.mp3tag.de/t/export-m3u-script-to-ignore-sub-folders/47955/6 "2020-02-23T09:29:55Z")

</div>

see File\>Options\>Playlist and find out if "Create playlist relative to workdir" helps

---

<div class="post-metadata">

### Author: ![RussianMix](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/cc9497/32.png) [@RussianMix](https://community.mp3tag.de/u/RussianMix)
#### Post date: [February 23, 2020, 9:38am UTC](https://community.mp3tag.de/t/export-m3u-script-to-ignore-sub-folders/47955/7 "2020-02-23T09:38:15Z")

</div>

> [@ohrenkino](#):
>
> see File\>Options\>Playlist and find out if " **Create playlist relative to workdir**" helps

Don't have this option, unless you mean `Entries relative from work directory` - `Enable this option, if you don't want full file paths in your playlist`, it made no difference checked or unchecked.

 ![options](https://community.mp3tag.de/uploads/default/original/2X/3/3003e34c33e948bff80d58732e061eaa982a283f.jpeg)

---

<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: [February 23, 2020, 11:00am UTC](https://community.mp3tag.de/t/export-m3u-script-to-ignore-sub-folders/47955/8 "2020-02-23T11:00:26Z")

</div>

> [@RussianMix](#):
>
> $filename(m3u,ansi)#EXTM3U $loop(%\_filename\_ext%)#EXTINF:%\_length\_seconds%,%artist% - %title% %\_path% $loopend()

I tried your script and the result is just one file (i have not ticked the option "One file per folder").  
So what is different?

---

<div class="post-metadata">

### Author: ![RussianMix](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/cc9497/32.png) [@RussianMix](https://community.mp3tag.de/u/RussianMix)
#### Post date: [February 23, 2020, 12:57pm UTC](https://community.mp3tag.de/t/export-m3u-script-to-ignore-sub-folders/47955/9 "2020-02-23T12:57:08Z")

</div>

There is no way to handle how Mp3Tag creating M3U files within export script other than specify file name and encoding.

Still weather to create one file or file for each sub folder is determined by Mp3Tag option " **One file per directory**" if checked it creates M3U file for each sub folder, if unchecked creates one M3U file with MP3 files from all directories, no other option.

This is limiting factor to doing what i intended.

I think only solution to my original question is workaround - create single M3U file trough export script then break it up using 3rd party program, any idea how to do it?

---

<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: [February 23, 2020, 1:01pm UTC](https://community.mp3tag.de/t/export-m3u-script-to-ignore-sub-folders/47955/10 "2020-02-23T13:01:25Z")

</div>

> [@RussianMix](#):
>
> however i cannot define variables.

See $put() and $get() to handle user-defined variables.  
[Exporting Tag and File Information – Mp3tag Documentation](https://docs.mp3tag.de/export/#export-scripting-functions)

Also, you can define a playlist name with string constants and viariable parts where the variable part could be %album% so that you get all the files from one album into one file.

---

<div class="post-metadata">

### Author: ![RussianMix](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/cc9497/32.png) [@RussianMix](https://community.mp3tag.de/u/RussianMix)
#### Post date: [February 23, 2020, 1:57pm UTC](https://community.mp3tag.de/t/export-m3u-script-to-ignore-sub-folders/47955/11 "2020-02-23T13:57:51Z")

</div>

> [@ohrenkino](#):
>
> See $put() and $get() to handle user-defined variables.

This variable cannot be used within nested loop, following does not work.

```
$filename(m3u,ansi)
$loop(%_folderpath%,1)

	$puts(grant_parent_folder_name,%_parent_directory%)
	$puts(parent_folder_name,%_directory%)

	$get(grant_parent_folder_name)
	$get(parent_folder_name)
	%_path%

	$loop(%_filename_ext%)

		getting $get(grant_parent_folder_name) 
		$get(parent_folder_name) 
		%_path%

	$loopend()

$loopend()

```

> [@ohrenkino](#):
>
> Also, you can define a playlist name with string constants and viariable parts where the variable part could be %album% so that you get all the files from one album into one file.

I'll try this however only works when you have ID3 tag set for mp3 files.

---

<div class="post-metadata">

### Author: ![dano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/dano/32/6_2.png) [@dano](https://community.mp3tag.de/u/dano)
#### Post date: [February 23, 2020, 2:22pm UTC](https://community.mp3tag.de/t/export-m3u-script-to-ignore-sub-folders/47955/12 "2020-02-23T14:22:45Z")

</div>

Use the Export function.  
Create two configurations:

```
Playlist Discs A Header.mte:
$filename($regexp(%_folderpath%,'\\(CD|Disc)\s*\d+\\$','\')---$regexp($regexp(%_folderpath%,'\\(CD|Disc)\s*\d+\\$','\'),'^.+\\([^\\]+)\\',$1).m3u,ansi)#EXTM3U$char(13)$char(10)

Playlist Discs B Body.mte:
$filename($regexp(%_folderpath%,'\\(CD|Disc)\s*\d+\\$','\')---$regexp($regexp(%_folderpath%,'\\(CD|Disc)\s*\d+\\$','\'),'^.+\\([^\\]+)\\',$1).m3u,ansi)$loop(%_filename_ext%)#EXTINF:%_length_seconds%,%artist% - %title%
%_filename_rel%
$loopend()

```

Select all files and run the first config with the option  
[X] One file per directory

Then run the second config with the options  
[X] Append data  
[X] One file per directory

You can also save this as action group.

---

<div class="post-metadata">

### Author: ![RussianMix](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/cc9497/32.png) [@RussianMix](https://community.mp3tag.de/u/RussianMix)
#### Post date: [February 23, 2020, 3:49pm UTC](https://community.mp3tag.de/t/export-m3u-script-to-ignore-sub-folders/47955/13 "2020-02-23T15:49:16Z")

</div>

> [@dano](#):
>
> Use the Export function.  
> Create two configurations:

That worked, with one minor bug, sometimes sub folders within album folder have different name from `CD` and `Disk` (or have greater depth than one sub folder) in this case your script still creates M3U within albums sub-folder.

**Edit:** Here is my regex-less tweak to fix folder issues.

```
Export Script 1.mte:
$filename($left(%_folderpath%,$add($len(%_workingpath%),$strchr($right(%_folderpath%,$distance(%_folderpath%,%_workingpath%)),\)))$left($right(%_folderpath%,$distance(%_folderpath%,%_workingpath%)),$sub($strchr($right(%_folderpath%,$distance(%_folderpath%,%_workingpath%)),\),1)).m3u,ansi)#EXTM3U

Export Script 2.mte:
$filename($left(%_folderpath%,$add($len(%_workingpath%),$strchr($right(%_folderpath%,$distance(%_folderpath%,%_workingpath%)),\)))$left($right(%_folderpath%,$distance(%_folderpath%,%_workingpath%)),$sub($strchr($right(%_folderpath%,$distance(%_folderpath%,%_workingpath%)),\),1)).m3u,ansi)$loop(%_filename_ext%)#EXTINF:%_length_seconds%,%artist% - %title%
%_path%
$loopend()

```

---

<div class="post-metadata">

### Author: ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)
#### Post date: [March 24, 2020, 3:55pm UTC](https://community.mp3tag.de/t/export-m3u-script-to-ignore-sub-folders/47955/14 "2020-03-24T15:55:18Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
