# Export to text: Conditional output based on loopend

**URL:** https://community.mp3tag.de/t/export-to-text-conditional-output-based-on-loopend/16555
**Category:** General Discussion
**Created:** [February 1, 2015, 7:44pm UTC](https://community.mp3tag.de/t/export-to-text-conditional-output-based-on-loopend/16555 "2015-02-01T19:44:30Z")
**Posts on this page:** 1
**Showing post:** 4

<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: [February 2, 2015, 7:28am UTC](https://community.mp3tag.de/t/export-to-text-conditional-output-based-on-loopend/16555/4 "2015-02-02T07:28:30Z")

</div>

> [@cdubjr](#):
>
> I Tried that and ran it through a JSON validator. Same issue. ...

I did not check the JSON code.

> [@cdubjr](#):
>
> ... What I am wondering is if I can conditionally output the comma based on whether or not the script is processing the last file in a folder or not. Is that possible?

It seems that you describe a problem with a comma separated list, and with a trailing comma at end of the list.  
There might be more than one possible solutions.  
One is, do not write a trailing comma after each array object, but write a leading comma before each following array object, starting from object #2.  
For the very first array object, suppress the leading comma.

(... this seems to be semantically correct, because the separator comma is indeed the connector between the previous and the following item, and the separator comma is indeed a property of the following item, and a leading separator comma is not defined for the first item in the list).

Example:

**01: $filename($getEnv('USERPROFILE')'\Desktop\Export.Whatever.txt',UTF-8)** 

**02: $loop(%\_filename\_ext%)$ifgreater(%\_counter%,1,',',)'{'  
03: '"trackNumber":"'$num(%TRACK%,2)'",'  
04: '"title":"'%TITLE%'",'  
05: '"artists":"'%ARTIST%'",'  
06: '"composers":"'%COMPOSER%'",'  
07: '"length":"'%\_length%'",'  
08: '"bitRate":"'[%\_bitrate%'kbps'[' '%\_vbr%]]'",'  
09: '"fileName":"'%\_filename\_ext%'",'  
10: '"fileSize":"'%\_file\_size%'"'  
11: '}'$loopend()**

 

DD.20150202.0928.CET, DD.20150202.1211.CET

 

See also ... the other way round ... a slightly other problem ...  
"Determine the last loop"  
... which needs a little bit more coding ... my proposal from there ...

 

[Determine the last loop inside loop?](https://community.mp3tag.de/t/7231/5)

 

DD.20150203.0913.CET

---

_[View the full topic](https://community.mp3tag.de/t/export-to-text-conditional-output-based-on-loopend/16555)._
