# export csv with foldername and total time

**URL:** https://community.mp3tag.de/t/export-csv-with-foldername-and-total-time/12016
**Category:** Export
**Created:** [May 16, 2011, 5:16pm UTC](https://community.mp3tag.de/t/export-csv-with-foldername-and-total-time/12016 "2011-05-16T17:16:40Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![hbfan](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/h/e36b37/32.png) [@hbfan](https://community.mp3tag.de/u/hbfan)
#### Post date: [May 16, 2011, 5:16pm UTC](https://community.mp3tag.de/t/export-csv-with-foldername-and-total-time/12016/1 "2011-05-16T17:16:40Z")

</div>

I need a simple export script that (basicaly) shows the Foldername and Total Time from all mp3-files within a folder.

Explanation: This export script should be usefull for a list of my audiobook collection. All new audiobooks will be located on an external disc and I'm creating a new csv-file that expands my collection (import in Excel and add to the existing list).

The following script is (nearly) working perfect:

$filename(%\_workingdir% Album List.txt,ansi)Folder and Total Length  
Folder$char(9)Dauer  
$loop(%\_parent\_directory%,1)%\_directory%$char(9)%\_total\_time%  
$loopend()  
Vers. 7.1 Created on %\_date%

Most of the audiobook-mp3s are located in one folder that is named "author - audiobookname" and the exportscript shows in one line the name of the folder and the total length of the audiobook. Unfortunately some of my audiobooks are organized in subfolders like "cd1", "cd2" and so on. The above script then shows the name of first subfolder instead of the main folder.

May I use other placeholders to get the requested information ? I tried to use %\_folderpath%, %\_folderpath\_rel% and %\_directory% but none of them worked.

... and before some asks why I don't use %album% as placeholder for the loop - first I'm cataloging the audiobooks and then I'm doing the tagging so there is no (good) album-tag in the mp3s...

Please help and/or advise to get this (hopefully simple) script running, thanks in advance.

hbforum

---

<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: [May 17, 2011, 6:26am UTC](https://community.mp3tag.de/t/export-csv-with-foldername-and-total-time/12016/2 "2011-05-17T06:26:17Z")

</div>

> [@hbfan](#):
>
> I need a simple export script that (basicaly) shows the Foldername and Total Time from all mp3-files within a folder. ...

**$filename($getEnv('USERPROFILE')'\Desktop\'%\_directory%' -- Duration.txt',ANSI)'Folder'$char(9)'Duration' %\_directory%$char(9)%\_total\_time%**

> [@hbfan](#):
>
> ... Unfortunately some of my audiobooks are organized in subfolders like "cd1", "cd2" and so on. ...

The simple way to solve the problem is ... for different cases you can create and run different scripts.

**$filename($getEnv('USERPROFILE')'\Desktop\'%\_workingdir%' -- Duration.txt',ANSI)'Folder'$char(9)'Duration' %\_workingdir%$char(9)%\_total\_time%**

Do you need ...  
... the duration of all tracks per one CD part ...  
... or ...  
... the duration of all tracks of all CD parts together from the entire audiobook?

DD.20110517.1033.CEST

---

<div class="post-metadata">

### Author: ![hbfan](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/h/e36b37/32.png) [@hbfan](https://community.mp3tag.de/u/hbfan)
#### Post date: [May 17, 2011, 7:17am UTC](https://community.mp3tag.de/t/export-csv-with-foldername-and-total-time/12016/3 "2011-05-17T07:17:22Z")

</div>

> [@DetlevD](#):
>
> Do you need ...  
> ... the duration of all tracks per one CD part ...  
> ... or ...  
> ... the duration of all tracks of all CD parts together from the entire audiobook?

I need the duration of all tracks of all CD parts from the entire audiobook (so it is really the "Total Time" :-).

As all new audiobooks are in one "main folder" I just need one script to collect the data for the audiobooks.

Thanks a lot for your kindly help 🙂

hbfan

---

<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: [May 17, 2011, 7:42am UTC](https://community.mp3tag.de/t/export-csv-with-foldername-and-total-time/12016/4 "2011-05-17T07:42:31Z")

</div>

> [@hbfan](#):
>
> I need the duration of all tracks of all CD parts from the entire audiobook (so it is really the "Total Time" :-).  
> As all new audiobooks are in one "main folder" I just need one script to collect the data for the audiobooks. ...

If one audiobook's root is a single folder including all related CD subfolders, then you can point Mp3tag to the audiobook folder as the working directory and use the second export script from post #2.  
You will get a text file on your desktop, which contains two lines, for example:

```
Folder Duration
2003 - The Yes Story.Gold 02:22:47

```

If you point the working directory to one level above, then you may get a result like this example:

```
Folder Duration
Yes 12:25:07

```

DD.20110517.1153.CEST

---

<div class="post-metadata">

### Author: ![hbfan](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/h/e36b37/32.png) [@hbfan](https://community.mp3tag.de/u/hbfan)
#### Post date: [May 17, 2011, 2:18pm UTC](https://community.mp3tag.de/t/export-csv-with-foldername-and-total-time/12016/5 "2011-05-17T14:18:10Z")

</div>

QUOTE (DetlevD @ May 17 2011, 11:42) \<{POST\_SNAPBACK}\>

If one audiobook's root is a single folder including all related CD subfolders, then you can point Mp3tag to the audiobook folder as the working directory and use the second export script from post #2.

You will get a text file on your desktop, which contains two lines, for example:

```
Folder Duration
2003 - The Yes Story.Gold 02:22:47

```

If you point the working directory to one level above, then you may get a result like this example:

```
Folder Duration
Yes 12:25:07

```

DD.20110517.1153.CEST

Thanks for the codes but they do not work. Maybe I should more explain my folder structure:

All new audiobooks where (temporarily) placed in one "root folder", here called "importfolder". Each audiobook has its own subfolder, that is named like "author - bookname". Some of the audiobooks do have subfolders for seperate cds.

My starting- = working-directory should be the importfolder and I want to catalog all audiobooks in this folder within one script, that exports the requested data (foldername + total duration) for each audiobook each in one line of the textfile.

Here is a sample of the folderstructure:

c:\importfolder\kathy reichs - deadly kiss  
c:\importfolder\patricia cornwell - predator\cd1  
c:\importfolder\patricia cornwell - predator\cd2\

I'm expecting a csv-file with the two entries:

kathy reichs - deadly kiss 04:15:23  
patricia cornwell - predator 06:12:34

I hope that clears my expectations to a script. The script in my startposting shows the following exportfile:

kathy reichs - deadly kiss 04:15:23  
cd1 06:12:34

What is the missing or wrong code in my script ?

Your help is much appreciated as I'm working for now on hours on this small export script, Thanks !

hbfan

---

<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: [May 17, 2011, 4:43pm UTC](https://community.mp3tag.de/t/export-csv-with-foldername-and-total-time/12016/6 "2011-05-17T16:43:44Z")

</div>

> [@hbfan](#):
>
> Thanks for the codes but they do not work. ...

Hmm, I gave you two export scripts, which do work, when one know how to apply them.

> [@hbfan](#):
>
> ... Maybe I should more explain my folder structure: ...

I do understand your folder organisation.  
Maybe there are some problems bundled together.

- The folder depth varies.
- There is no standard tag-field data to use for looping.
- Maybe Mp3tag is not able to loop on calculated folder parts resp. substrings of pseudo tag-fields like %\_path% or %\_folderpath%.

The pseudo tag-fields %\_directory% and %\_parent\_direxctory% are related to the audiofile in a relative manner, which means, one step up resp. two steps up from the point of view of the audiofile.

But you want look in an absolute manner to a common folder level within the folderpath, which starts at the diskroot resp. in one designated master folder.

> [@hbfan](#):
>
> ...  
> Here is a sample of the folderstructure:  
> c:\importfolder\kathy reichs - deadly kiss  
> c:\importfolder\patricia cornwell - predator\cd1  
> c:\importfolder\patricia cornwell - predator\cd2  
> ...

You want to get the sum of playtime of all audiofiles within each 'Artist - Album' folder, including all audiofiles in possible subfolders, summed up per 'Artist - Album' folder, beneath the main root folder 'c:\importfolder'.

The problem will loose its complexity, when you are willing to create one or more user defined tag-fields.  
For example, you can split the folderpath into its components, and use the common part of the folderpath, stored in a tag-field, as the argument in an export $loop function.

See there to get an impression what could be done:  
[Easy way to get directory names above Parent?](https://community.mp3tag.de/t/9324/1)  
[mit \_DIRECTORY Überordner umbenennen (zb bei 2xCD)](https://community.mp3tag.de/t/10728/1)

You can try to store the result from the following expression into an user defined tag-field within each audiofile and run an export loop on this tag-field over all files and sum up the length in seconds resp. use only the first item per loop and evaluate the placeholder %\_total\_time%.

**%\_workingpath%$regexp($replace('\*'%\_folderpath%,'\*'%\_workingpath%,),'^(.+?)\\\\.\*$','$1')'\'**

> [@hbfan](#):
>
> ...I'm expecting a csv-file with the two entries:  
> kathy reichs - deadly kiss 04:15:23  
> patricia cornwell - predator 06:12:34  
> ...

I assume you want to create a TSV file using the TAB character created by $char(9) as the delimiter between the items?

Using the proposal from above I am able to create a text output like this ...

```
Duration in Seconds ==> Folderpath

  2458 ==> M:\MUSIK\ROCK\Y\Yes\1969 - Yes\
  1082 ==> M:\MUSIK\ROCK\Y\Yes\1970 - Something's Coming\
  2452 ==> M:\MUSIK\ROCK\Y\Yes\1971 - The Yes Album\
  2429 ==> M:\MUSIK\ROCK\Y\Yes\1972 - Fragile\
  4530 ==> M:\MUSIK\ROCK\Y\Yes\1972 - Close To The Edge\
  4428 ==> M:\MUSIK\ROCK\Y\Yes\1993 - Affirmative\
  9380 ==> M:\MUSIK\ROCK\Y\Yes\2003 - The Ultimate Yes (128kB)\
  9381 ==> M:\MUSIK\ROCK\Y\Yes\2003 - The Ultimate Yes.35th AC\
  8567 ==> M:\MUSIK\ROCK\Y\Yes\2003 - The Yes Story.Gold\

 44707 = Total Seconds
12:25:07 = Total Time

```

DD.20110517.2058.CEST

---

<div class="post-metadata">

### Author: ![foo\_peter](https://community.mp3tag.de/user_avatar/community.mp3tag.de/foo_peter/32/156_2.png) [@foo\_peter](https://community.mp3tag.de/u/foo_peter)
#### Post date: [May 17, 2011, 4:59pm UTC](https://community.mp3tag.de/t/export-csv-with-foldername-and-total-time/12016/7 "2011-05-17T16:59:09Z")

</div>

leider ist mein englisch viel zu schlecht ich antworte in der Hoffnung das evtl jemand damit etwas anfangen kann! ....

```
$filename(Album List.csv)Artist YEAR ALBUM TOTALTIME
$loop(%_folderpath%)
$if($eql($folderdepth(%_folderpath%),$folderdepth(%_workingpath%)),,%artist% - %album% $if(%year%, - '['%_total_time%']',))$loop(%_directory%)$loopend()$loopend()$loop(%_filename_ext%)$if($eql($folderdepth(%_folderpath%),$folderdepth(%_workingpath%)),
%artist% - %album% - $if(%year%,- '['%_total_time%']',),)$loopend()

```

oder besser noch

```
$filename(albums-only.csv)"Folderpath";"Album";"Totalfiles";"Gesamtlänge"
$loop(%album%%_folderpath%,1)%_folderpath%; %album%; %_total_files%; %_total_time%
$loopend()
```

---

<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: [May 18, 2011, 5:21am UTC](https://community.mp3tag.de/t/export-csv-with-foldername-and-total-time/12016/8 "2011-05-18T05:21:52Z")

</div>

> [@hbfan](#):
>
> ... I want to catalog all audiobooks in this folder within one script, that exports the requested data (foldername + total duration) for each audiobook each in one line of the textfile. ...

> [@](#):
>
> ... and before some asks why I don't use %album% as placeholder for the loop - first I'm cataloging the audiobooks and then I'm doing the tagging so there is no (good) album-tag in the mp3s ...

'hbfan', your project has something of 'putting the cart before the horse'.  
As user 'foo\_peter' has demonstrated in post #7, the task of creating a report about overall playtime per Audiobook Album can be easily reduced to some simple scripting lines, when the involved tag-fields and their content are available.

The first step should be to fill the tag-fields with their associated data.  
The second step can be to create the report, using the content from the tag-fields as the guide line for the report loop.

DD.20110518.0925.CEST

---

<div class="post-metadata">

### Author: ![hbfan](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/h/e36b37/32.png) [@hbfan](https://community.mp3tag.de/u/hbfan)
#### Post date: [May 18, 2011, 3:52pm UTC](https://community.mp3tag.de/t/export-csv-with-foldername-and-total-time/12016/9 "2011-05-18T15:52:13Z")

</div>

First of all - thanks a lot to DetlevD and foo\_peter for your answers. Sorry to DetlevD for my "It does not work"-comment, of course they work correct but I meant it as "work not in the way I need it".

> [@DetlevD](#):
>
> 'hbfan', your project has something of 'putting the cart before the horse'.

Yes, you're totally right, as we say in Germany "ziehe ich das Pferd von hinten auf". Best would be indeed to work with a tagged database but I do not have a such one. I'm working with an audiobook collection of more hat 1.000 audiobooks including more than 50.000 mp3-files and it will cost me some months to tag them.

To get an quick overview I only have the foldername and want to get the total duration of each folder. I could split the folderpath into seperate parts, store them in user defined tags but that would need a lot of time and it would be just for one export (after that I would delete this tag..). So I#m still searching for a "3-line-script" that shows the foldername plus the total duration of files in this folder.. maybe some scipt-genius can post it.

Thanks again from sunny Germany  
hbfan

---

<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: [May 18, 2011, 4:25pm UTC](https://community.mp3tag.de/t/export-csv-with-foldername-and-total-time/12016/10 "2011-05-18T16:25:04Z")

</div>

> [@hbfan](#):
>
> ... Best would be indeed to work with a tagged database but I do not have a such one. I'm working with an audiobook collection of more hat 1.000 audiobooks including more than 50.000 mp3-files ... To get an quick overview I only have the foldername and want to get the total duration of each folder. ... So I#m still searching for a "3-line-script" that shows the foldername plus the total duration of files in this folder ...

Perhaps I understand you all wrong, but what would be if you take Mp3tag to reduce the amount of effort and time on tagging the 1k albums resp. 50k files?

You know already the artist name and the album name (from the foldername), so put them both, at least the album name, into the files.  
Then run a loop per album and detect total time per album.  
At that moment, nothing seems to be easier than this.  
Depending on your hardware it will cost some time to fill the tag-field ALBUM into 50k files, but it is worth to do so, because the export script can be rather simple.

You do not need to do this in one run.  
Better to split the work into several steps:

- Filter for albums with only one CD.
- Filter for albums with more than one CD.

Then get resp. 'let Mp3tag guess' the album name from the %\_directory% resp. from the %parent\_directory% pseudo tag-field.  
It's all simple standard work within Mp3tag.

For example (albums with only one CD, that means no CD subfolders):  
Aktion: Tag-Felder importieren  
Tag-Feld: %\_directory%  
Formatstring: %artist% - %album%

For example (albums with more than one CD, having CD subfolders):  
Aktion: Tag-Felder importieren  
Tag-Feld: %\_parent\_directory%  
Formatstring: %artist% - %album%

Once you have a tag-field ALBUM with proper content, then do the export of total times per album.

DD.20110518.2026.CEST

---

<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: [May 18, 2011, 4:53pm UTC](https://community.mp3tag.de/t/export-csv-with-foldername-and-total-time/12016/11 "2011-05-18T16:53:26Z")

</div>

```
$filename(Album List.txt,ansi)Folder and Total Length
Folder$char(9)Dauer

$loop($regexp(%_folderpath%,'cd *\d+\\\\$',,1),1)$if($eql($regexp(%_directory%,'^cd *\d+$',,1),%_directory%),%_directory%,%_parent_directory%)$char(9)%_total_time%
$loopend()
```

---

<div class="post-metadata">

### Author: ![hbfan](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/h/e36b37/32.png) [@hbfan](https://community.mp3tag.de/u/hbfan)
#### Post date: [May 19, 2011, 6:32pm UTC](https://community.mp3tag.de/t/export-csv-with-foldername-and-total-time/12016/12 "2011-05-19T18:32:03Z")

</div>

There is (only) one word to say to the 4-line script of 'dano': perfect ![:rolleyes:](https://community.mp3tag.de/uploads/default/original/1X/3a79e8b0b7d169b30216785521d7c6f4f895c421.gif ":rolleyes:")

Tested with the audiobook collection and it does exact what it should do - thanks a lot.

hbfan

... is there any hidden switch I could not find so far to set this thread as "closed" or "solved" ?

---

<div class="post-metadata">

### Author: ![hbfan](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/h/e36b37/32.png) [@hbfan](https://community.mp3tag.de/u/hbfan)
#### Post date: [May 20, 2011, 3:16am UTC](https://community.mp3tag.de/t/export-csv-with-foldername-and-total-time/12016/13 "2011-05-20T03:16:30Z")

</div>

> [@DetlevD](#):
>
> You do not need to do this in one run.  
> Better to split the work into several steps:
> 
> - Filter for albums with only one CD.
> - Filter for albums with more than one CD.

'DetlevD', Thanks to you as well. Your scripts and input will help me in tagging this mass of mp3s in a propper way.

hbfan

---

<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: [May 20, 2011, 11:47am UTC](https://community.mp3tag.de/t/export-csv-with-foldername-and-total-time/12016/14 "2011-05-20T11:47:56Z")

</div>

Here is a variation of Dano's proposal from post #11.

**$filename($getEnv('USERPROFILE')'\Desktop\'%\_workingdir%' -- Folder Total Time.txt',ANSI)'Folder Total Time' $loop($regexp(%\_folderpath%,'\,\*\s\*CD\s\*\d+\\\\$',,1),1)$num(%\_counter%,3)'|'%\_total\_time%'|'$regexp(%\_folderpath%,'\,\*\s\*CD\s\*\d+\\\\$',,1) $loopend()$repeat('=',3)'|'%\_total\_time%'|'$repeat('=',3)** 

Example output:

```
Folder Total Time
001|07:17:52|M:\VA COMPILATIONS\0-9\100 Prozent Rock\
002|01:11:25|M:\VA COMPILATIONS\0-9\2 Meter Sessies Vol.4\
...
234|01:31:43|M:\VA COMPILATIONS\W\Wuppstock 1973\
===|14 Days, 20:20:03|===

```

DD.20110520.1548.CEST
