• Isadora
  • Get it
  • Forum
  • Help
  • ADD-ONS
  • Newsletter
  • Impressum
  • Dsgvo
  • Impressum
Forum
    • Categories
    • Recent
    • Popular
    • Tags
    • Register
    • Login

    Use Javascript to test a Text file for existence and content.

    How To... ?
    1
    1
    652
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DusXD
      DusX Tech Staff
      last edited by

      You can use Javascript to read text files, you can also use Javascript to do error handling.

      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.

      Here is a quick script that will tell you if a Text file exist, and if its Empty or Not.
      =========================================

      function main() {

      var state; // State or 0 = good txt, 1 = Empty, 2 = Read Error
      var txt;
      try { 
      txt = read(arguments[0]);
      state = 0;
      }
      catch(err) {
      // ERROR: unreadable file, or file doesn't exist
      txt = err.message;
      state = 2;
      }

      if (txt == ""){
      // text file exists but is empty
      state = 1;
      }

      return [txt,state];

      }

      =========================================

      @Michel how do we format code again.. its pretty script still installed?

      Troikatronix Technical Support

      • New Support Ticket Link: https://support.troikatronix.com/support/tickets/new
      • Isadora Add-ons: https://troikatronix.com/add-ons/
      • My Add-ons: https://troikatronix.com/add-ons/?u=dusx

      Running: Win 11 64bit, i7, M.2 PCIe SSD's, 32gb DDR4, nVidia GTX 4070 | located in Ontario Canada.

      1 Reply Last reply Reply Quote 1
      • First post
        Last post