# Export Script with $if statement

**URL:** https://community.mp3tag.de/t/export-script-with-if-statement/15978
**Category:** Support
**Created:** [August 8, 2014, 1:02am UTC](https://community.mp3tag.de/t/export-script-with-if-statement/15978 "2014-08-08T01:02:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rko31415](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/f19dbf/32.png) [@rko31415](https://community.mp3tag.de/u/rko31415)
#### Post date: [August 8, 2014, 1:02am UTC](https://community.mp3tag.de/t/export-script-with-if-statement/15978/1 "2014-08-08T01:02:29Z")

</div>

I store "listened to" information in the track field %track%=zzzz or qqqq means I have listened to the podcast or it's in the queue. (this is due to a limitation of Copernic which I use to index my collection)

I want to identify all finished albums, i.e., albums where the podcasts all have zzzz or qqqq.

I set up the following export script:

$filename(Finished-Albums.m3u8,utf-8)  
$loop(%album%)$loop(%album%)  
$if(%track%,$puts(counttracks,$add($get(counttracks),1)),)  
$loopend()  
$if($eql(%\_max\_counter%,$get(counttracks)),'#Album Finished: '$if2(%album%,-- empty --)  
,)  
$puts(counttracks,0)  
$loopend()

Investigation shows that the $if condition is being ignored ... that my user-defined field counttracks is being incremented to the total number of albums regardless whether %track% is present or not.

Thoughts?

---

<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: [August 8, 2014, 4:42am UTC](https://community.mp3tag.de/t/export-script-with-if-statement/15978/2 "2014-08-08T04:42:51Z")

</div>

> [@rko31415](#):
>
> ... Investigation shows that the $if condition is being ignored ... that my user-defined field counttracks is being incremented to the total number of albums regardless whether %track% is present or not. Thoughts?

Adapt the right coding for $put from there ...  
[Export scripting: unexpected variable assignment between loops](https://community.mp3tag.de/t/15746/2)

Export script example 1:

**1: $filename($getEnv('USERPROFILE')'\Desktop\Finished-Albums.txt',UTF-8)** 

**2: $loop(%ALBUM%)$loop(%\_path%)$puts(TrackCount,$if(%TRACK%,$add(1,$get(TrackCount)),$get(TrackCount)))$loopend()  
3: $if($eql(%\_max\_counter%,$get(TrackCount)),' Album finished: ','# Album not finished: ')$if2(%ALBUM%,'[no album name]')$puts(TrackCount,0)$loopend()**

 

Export script example 2:

 **01: $filename($getEnv('USERPROFILE')'\Desktop\Finished-Albums.txt',UTF-8)$puts(** 

**02: )$loop(1,1)$puts(crlf,$char(13)$char(10))$puts(br,'{br}')$loopend()$replace(  
03:  
04: $loop(%ALBUM%)$replace(  
05:  
06: 'ALBUM: '$put(AlbumCount,$add(1,$get(AlbumCount)))' : '%ALBUM%$get(br)  
07:  
08: $loop(%\_path%)$replace(  
09:  
10: 'File : '$put(FileCount,$add(1,$get(FileCount)))' : '%\_path%$get(br)  
11:  
12: $puts(TrackCount,$if(%TRACK%,$add(1,$get(TrackCount)),$get(TrackCount)))  
13:  
14: ,$get(crlf),,$get(br),$get(crlf))$loopend()  
15:  
16: 'FileCount : '$get(FileCount)$get(br)  
17: 'TrackCount: '$get(TrackCount)$get(br)  
18:  
19: $if($eql($get(FileCount),$get(TrackCount)),'# Album finished: ','### Album not finished: ')$if2(%ALBUM%,'[no album name]')  
20: $get(br)$get(br)  
21:  
22: $puts(FileCount,0)  
23: $puts(TrackCount,0)  
24:  
25: ,$get(crlf),,$get(br),$get(crlf))$loopend()  
26: ,$get(crlf),,$get(br),$get(crlf))**

 

DD.20140808.1044.CEST

---

<div class="post-metadata">

### Author: ![rko31415](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/f19dbf/32.png) [@rko31415](https://community.mp3tag.de/u/rko31415)
#### Post date: [August 8, 2014, 9:40am UTC](https://community.mp3tag.de/t/export-script-with-if-statement/15978/3 "2014-08-08T09:40:27Z")

</div>

Works great. Thanks. I never would have figured that out.  
Great product!

---

<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:25pm UTC](https://community.mp3tag.de/t/export-script-with-if-statement/15978/4 "2026-02-09T12:25:10Z")

</div>


