Help with Export

In THIS thread I receive help from ohrenkino and that script with two loops served me well until now.

The problem is that when I try to export from multiple folders at once, if some of the albums folder have sub-folders numbering the discs, the result that is written on the TXT file is just the name of that sub-folder. Some similar to this:

CD 1
track1
track2
track3 

CD 2
track1
track2
track3

Another problem with the actual script is that when two albums folders have exactly the same sub-folder name (example: both have a Disc 1 sub-folder) the export result ignore the Disc 1 folder of the second one and just proceed writing the sub-folders with different numbers that do not exist on the first folder. I mean, suppose that 2 album folders have this structure:
Album A have "Disc 1" and "Disc 2" sub-folders.
Album B have "Disc 1", "Disc 2" and "Disc 3" sub-folders.
Using the actual script the TXT will have the tracks from the "Disc 1" and "Disc 2" sub-folders from Album A listed, but no from the Album B, Album B will only have the tracks listed starting from "Disc 3".

I'm searching for something that result on something similar to this:

Album Name
CD 1
track1
track2
track3 

CD 2
track1
track2
track3

Anyone can give some advice or a answer to improve the previous script making it able to supply this need?

Thanks in advance for all help provided.

Can't you filter for those albums that have the CD in the folder name?

Then you could add another loop on the _parentdirectory

$filename(txt,utf-8)$loop(%_parentdirectory%)%album%$loop(%_directory%)%_directory%
$loop(%_filename%)%_filename%
$loopend()
$loopend()$loopend()