• Products
    • Isadora
    • Get It
    • ADD-ONS
    • IzzyCast
    • Get It
  • Forum
  • Help
  • Werkstatt
  • Newsletter
  • Impressum
  • Dsgvo
  • Press
  • Isadora
  • Get It
  • ADD-ONS
  • IzzyCast
  • Get It
  • Press
  • Dsgvo
  • Impressum

Navigation

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags

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

    How To... ?
    1
    1
    868
    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.
    • DusX
      DusX Izzy Guru 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 Professional Services
      https://troikatronix.com/professional-services

      🎫 Support Tickets
      https://support.troikatronix.com/support/tickets/new

      💻 Add-ons
      https://troikatronix.com/add-ons/?u=dusx

      🧪 GitHub Projects
      https://github.com/rwebber

      🖥️ Win11 | i7 | RTX 4070 | 32GB RAM | Ontario, Canada

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