# 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:** 1
**Showing post:** 2

<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

---

_[View the full topic](https://community.mp3tag.de/t/export-script-with-if-statement/15978)._
