Facility Control

 View Only
  • 1.  Read Folder List in Dashboard

    Posted 11-18-2022 09:41
    Is it possible to have Dashboard read a list of files from a folder? For example, we give the clients a folder then can add their homemade graphics to and then let them choose a graphic to put on air (Xpression) from Dashboard.

    We currently have a work around using custom software that watches a folder and updates a JSON file when the contents of the folder changes. Then we read that JSON file in Dashboard with scripting.

    Also, I believe this can be done through FTP but that has the added step of running an FTP server, which seems like overkill. So a non-FTP solution is preferable.

    Thanks.

    ------------------------------
    JohnCorigliano
    Senior Software Engineer
    ISC
    ------------------------------


  • 2.  RE: Read Folder List in Dashboard

    Posted 11-18-2022 16:20
    Hi John
    For your local filesytem, you can use ogscript.post('FILE_URL_GOES_HERE', null); to get a list of filenames (one name on each line).

    var files = ogscript.post('.', null).split('\n');
    
    for (var i = 0;i < files.length; i++)
    {
       ogscript.debug(files[i]);
    }
    ​


    ------------------------------
    James Peltzer
    Ross Video
    ------------------------------



  • 3.  RE: Read Folder List in Dashboard

    Posted 11-21-2022 10:20
    Thanks. Works great except I had to add the protocol:

    var files = ogscript.post("file:/D:/Clients/UserGraphics", null).split('\n');

    ------------------------------
    JohnCorigliano
    Senior Software Engineer
    ISC
    ------------------------------



  • 4.  RE: Read Folder List in Dashboard

    Posted 11-21-2022 10:44
    Yes - the code expects a URL format. I used the '.' to list the current directory (you can also use relative URLs for sub-folders in the same parent as the panel).  If you want to browse arbitrary locations on the drive, you will need to use the file URL format.

    ------------------------------
    James Peltzer
    Ross Video
    ------------------------------



  • 5.  RE: Read Folder List in Dashboard

    Posted 07-01-2023 15:55

    iam not a software engg to write a code , but i found this is so useful for me , can you suggest me how can i get those file as constraint value  in dropdown list rather then in debug . if i can get in dropdown then i can easly solve my broadcast problem alot. 



    ------------------------------
    sunil Blank
    Freelancer Graphics Designer
    Freelancer

    ------------------------------



  • 6.  RE: Read Folder List in Dashboard

    Posted 07-03-2023 07:53

    Frankly there is a ton of "traps" when it comes to reading files from a folder... I've been working on someting similar earlier this summer, and found most of them, I hope...
    Anyways, below is the code for a dashboard that will look up the files in a folder names "images" in the same folder as your DashBoard, regardless of where it is on whatever computer you copy it into, and then updates a dropdown with a choice constraint like you ask for above.

    <abs contexttype="opengear" gridsize="10" id="_top" keepalive="false" style="">
       <meta>
          <params>
             <param access="1" constrainttype="INT_CHOICE" name="selectFile" oid="selectFile" precision="0" type="INT32" value="0" widget="combo">
                <constraint key="0">---</constraint>
             </param>
          </params>
       </meta>
       <button buttontype="push" height="70" left="30" name="Get Files" top="30" width="100">
          <task tasktype="ogscript">var dashURL = decodeURI(ogscript.getPanelRelativeURL('images')); //Get the full path to /Images folder wherever the dashboard is.
    var files = ogscript.post(dashURL, null); // Get an array of files in the folder in the line above.

    if(files != null) { //Check if the folder exists at all.
       files = files.split('\n'); //create array from return if folder exists.
       if(files.length &gt; 1) { //Check if number of files is greater than 1. Empty folder still returns as 1 file with value of ''.
          var index = files.indexOf(''); //Get the index of the '' value entry in array
          if(index &gt; -1) { // Only splice array if item is found
             files.splice(index, 1); //Remove the found '' (if any), and one item only.
          }
          var arr = ['---']; //Prepare emtpy array for key/value pairs. I usually add '---' at the top for an "empty" choice for the dropdown.
          for (var i = 0; i &lt; files.length; i++) { //Go through each entry in the array and push key/value pair into the prepared array.
             arr.push({key:i,value:files[i]});
          }

          var choiceConstraint = params.createIntChoiceConstraint(arr); //Create an intChoiceConstraint from the key/value array.
          params.replaceConstraint('selectFile', choiceConstraint); //Replace the choice constraints in the dropdown parameter with the choice constraints created above.

          params.setValue('selectFile', 0, 0); //Set the choice in the dropdown to the first option wich would be --- in this example.

       } else {
          ogscript.debug('Folder is empty...');
       }
    }

    else {
       ogscript.debug('Folder does not exist...');
    }</task>
       </button>
       <param expand="true" height="30" left="130" oid="selectFile" top="120" width="220"/>
       <label height="30" left="30" name="Select: " style="txt-align:east" top="120" width="100"/>
       <label height="70" left="150" name="&lt;html&gt;For this to work, you must have a folder names &quot;images&quot; in the&lt;br/&gt;same folder as your dashboad.&lt;/html&gt;" style="txt-align:west;" top="30" width="470"/>
    </abs>

    Have fun! :D And do keep us posted about what you're doing. Allways fun to see end results. 



    ------------------------------
    Aleksander Stalsberg
    Inland Norway University of Applied Sciences/Lillehammer Icehockey Club
    Norway
    ------------------------------



  • 7.  RE: Read Folder List in Dashboard

    Posted 07-20-2023 12:39

    Thank you i will give a try and post the result



    ------------------------------
    sunil Blank
    Freelancer Graphics Designer
    Freelancer
    Kathmandu Nepal
    ------------------------------



  • 8.  RE: Read Folder List in Dashboard

    Posted 07-03-2023 09:11

    Is there a way to handle special characters returned from this as well @James Peltzer ?
    As of now, any Norwegian letters ÆØÅ returns just as questionmarks, and I cannot URI encode/decode them for that matter.

    Is there a way I'm missing here?



    ------------------------------
    Aleksander Stalsberg
    Inland Norway University of Applied Sciences/Lillehammer Icehockey Club
    Norway
    ------------------------------