# Can't get total albums script to work

**URL:** https://community.mp3tag.de/t/cant-get-total-albums-script-to-work/3777
**Category:** Support
**Created:** [September 17, 2006, 4:43pm UTC](https://community.mp3tag.de/t/cant-get-total-albums-script-to-work/3777 "2006-09-17T16:43:30Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Zelbinian](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/z/43a26b/32.png) [@Zelbinian](https://community.mp3tag.de/u/Zelbinian)
#### Post date: [September 17, 2006, 4:43pm UTC](https://community.mp3tag.de/t/cant-get-total-albums-script-to-work/3777/1 "2006-09-17T16:43:30Z")

</div>

I've spent hours on this. :frustration: After I finally figured out that, for some un-Godly reason, %track% and %\_total% return tracknumbers in different formats, I'm still running into problems. Basically, I want this loop to sort by album, and increment a counter variable everytime it finds a complete album, this telling me how many complete albums I have in any folder.

Here's my code (carriage returns are entered in for readability):

```
List compiled by %_app%
Updated:'['COLOR="Blue"']'%_date%'['/COLOR']'
$puts(no_albums,0)
$loop(%album%)
$if($eql($left(%track%,2),%_total%),$puts(no_albums,$add(1,$get(no_albums))),)
$loopend()
Added:

'['COLOR="Blue"']''['SIZE="5"']'MUSIC'['/COLOR']' - '['COLOR="Red"']'$get(no_albums) Albums'['/COLOR']' and change

```

For some reason, it outputs zero, even though when change $puts to $put it returns numbers other than zero. Even this is weird. I was testing it on an folder with 2 albums and a single track in it. The count it should have returned while looping was 1, 2. It returned 1, 2, 6. I have NO idea where that 6 is coming from, especially since no\_albums can only be increased by one and that output occurs EVERYTIME that function is called.

So, not only is the function being magically called a 3rd time, it's also being increased magically by 4. Can anyone help?!? Argghghg.

---

<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: [September 17, 2006, 6:02pm UTC](https://community.mp3tag.de/t/cant-get-total-albums-script-to-work/3777/2 "2006-09-17T18:02:13Z")

</div>

```
List compiled by %_app%
Updated:'['COLOR="Blue"']'%_date%'['/COLOR']'
$loop(%album%)

$puts(no_albums,$if(%track%,$if($eql($num(%track%,2),$num(%_total%,2)),$add(1,$get(no_albums)),$get(no_albums)),$get(no_albums)))

$loopend()

```

and don't use $puts(no\_albums,0)

---

<div class="post-metadata">

### Author: ![Zelbinian](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/z/43a26b/32.png) [@Zelbinian](https://community.mp3tag.de/u/Zelbinian)
#### Post date: [September 17, 2006, 9:49pm UTC](https://community.mp3tag.de/t/cant-get-total-albums-script-to-work/3777/3 "2006-09-17T21:49:20Z")

</div>

QUOTE (dano @ Sep 18 2006, 06:02) \<{POST\_SNAPBACK}\>

 List compiled by %\_app%

```
Updated:'['COLOR="Blue"']'%_date%'['/COLOR']'
$loop(%album%)

$puts(no_albums,$if(%track%,$if($eql($num(%track%,2),$num(%_total%,2)),$add(1,$get(no_albums)),$get(no_albums)),$get(no_albums)))

$loopend()

```

and don't use $puts(no\_albums,0)

Thanks, that works, but . . . could someone perhaps explain to me why that code works and what I was using didn't? I mean, I mostly get why yours works. You make sure to update the variable everytime through the loop, either with a new value or the previous one. But that $if(%track%... statement confuses me. How does that make the distinction between a file that is part of an album and a file that isn't? The way that I have my media library set up it's probably not gonna matter, but in this case the program is sure execute that then statement for every single one of my 4100+ mp3s instead of saving some processing power by skipping over the ones that it knows are not part of an album.

Mostly, I'm confused about why my code _doesn't_ work . . .

---

<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: [February 9, 2026, 12:19pm UTC](https://community.mp3tag.de/t/cant-get-total-albums-script-to-work/3777/4 "2026-02-09T12:19:53Z")

</div>


