export csv with foldername and total time

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


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

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?


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 :slight_smile:


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


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


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 !


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

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.

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?
mit _DIRECTORY √úberordner umbenennen (zb bei 2xCD)

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


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


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

$loop(%album%%_folderpath%,1)%_folderpath%; %album%;  %_total_files%; %_total_time%

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


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

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

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.


$filename(Album List.txt,ansi)Folder and Total Length

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

There is (only) one word to say to the 4-line script of 'dano': perfect :rolleyes:

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


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

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


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