<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Use Javascript to test a Text file for existence and content.]]></title><description><![CDATA[<p>You can use Javascript to read text files, you can also use Javascript to do error handling.</p><p>So its possible to use Javascript to Try reading a file, and determine if the file is available (exists and is readable as text) by checking for an error.</p><p>Here is a quick script that will tell you if a Text file exist, and if its Empty or Not.<br />=========================================</p><p>function main()
{</p><p>var state; // State or 0 = good txt, 1 = Empty, 2 = Read Error<br />var txt;<br />try {  <br />txt = read(arguments[0]);<br />state = 0;<br />}<br />catch(err) {<br />// ERROR: unreadable file, or file doesn't exist<br />txt = err.message;<br />state = 2;<br />}</p>
<p>if (txt == ""){
<br />// text file exists but is empty<br />	state = 1;
<br />	}
</p>
<p>return [txt,state];</p>
<p>
}</p><p>=========================================<br /></p><p><a class="plugin-mentions-user plugin-mentions-a" href="https://community.troikatronix.com/uid/7">@Michel</a> how do we format code again.. its pretty script still installed?</p>]]></description><link>https://community.troikatronix.com/topic/5119/use-javascript-to-test-a-text-file-for-existence-and-content</link><generator>RSS for Node</generator><lastBuildDate>Mon, 12 Oct 2026 08:51:52 GMT</lastBuildDate><atom:link href="https://community.troikatronix.com/topic/5119.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 23 Mar 2018 18:26:35 GMT</pubDate><ttl>60</ttl></channel></rss>