1 Reply Latest reply on Jun 17, 2016 11:26 AM by 1CM69

    Using an Array for File Types

    1CM69 Level 1

      Hi,

       

      I am attempting to make some changes to my script to basically prune it down a little.

       

      My original script only allowed for the use of a handful of File Types and although the procedure to open each of these file types meant 4 lines of code each, I was fairly happy with that.

       

      Now, however I wish to extend the bounds of the original handful of File Types so thought that containing them in an Array would be a better option.

       

      I am stuck, I cannot seem to be able to pull the required extension from the Array without an error occuring. Here is a snippet of what I have so far.

       

      var FILE_TYPE, FTlen, i;
      FILE_TYPE = [".orf", ".tif", ".tiff", ".jpg", ".jpeg"];
      FTlen = FILE_TYPE.length;
      for (i = 0; i < FTlen; i++){
      var SEARCH_MASK = "*" + FILE_TYPE[i];
      var DARKfileList = DARKinputFolder.getFiles(SEARCH_MASK);}
      
      
      if (DARKfileList.length <= 0){
      for (i = 0; i < FTlen; i++){
      var SEARCH_MASK = "*" + FILE_TYPE[i];
      var DARKfileList = DARKinputFolder.getFiles(SEARCH_MASK);}
      }
      
      
       if (DARKfileList.length == 0)
      {
          alert('The DARK FRAME folder you have chosen is either empty or does not contain image files of the correct type.\r\rPlease locate & select the correct image folder.','DARK FRAME folder error');
          DFgroup.DFlabel.text = 'No DARK FRAMES folder has been selected...';
          DFdefault = '';
          DFgroup.DFlabelQ.text = '';
          }
      

       

      What happens now when I run my script is that the folder browser opens as it should, I choose a folder with known file types matching the Array but it immediately shows me the Alert message that the folder does not contain images of the correct type.

       

      Any help would be appreciated.

       

      Kind regards...,

        • 1. Re: Using an Array for File Types
          1CM69 Level 1

          OK, I have it working somewhat but it is still missing part of the 'else' part of the main 'if' statement, here's the code now, possibly could be tidied up:

           

          DFgroup.DFBtn.onClick = function(){   
              DFdefault = new Folder(DARKinputFolder); //stores the current folder in case of cancel.   
              DFdefault = Folder.selectDialog('****Please Select The Folder Where Your DARK FRAMES Are Located****',DARKinputFolder);
              if ( DFdefault != null ) {
            DARKinputFolder = DFdefault.fsName.toString()
                                DFgroup.DFlabel.text = DARKinputFolder;
          
          
          if(DFdefault){DARKinputFolder = DFdefault}; //if cancel is hit, this statement becomes false, and myFolder remains untouched.   
              //if it's true, then the selected folder from the holdFolder is transferred to myfolder. 
          if (DARKfileList.length <= 0)
          {
          var FILE_TYPE, FTlen, i;
          FILE_TYPE = [".orf", ".tif", ".tiff", ".jpg", ".jpeg"];
          FTlen = FILE_TYPE.length;
          for (i = 0; i < FTlen; i++){
          var SEARCH_MASK = "*" + FILE_TYPE[i];
          var DARKfileList = DARKinputFolder.getFiles(SEARCH_MASK);
          }
          }
          end
            if (DARKfileList.length == 0)
          {
              alert('The DARK FRAME folder you have chosen is either empty or does not contain image files of the correct type.\r\rPlease locate & select the correct image folder.','DARK FRAME folder error');
              DFgroup.DFlabel.text = 'No DARK FRAMES folder has been selected...';
              DFdefault = '';
              DFgroup.DFlabelQ.text = '';
              }
          else{                     
                                DFgroup.DFlabelQ.text = '[' + DARKfileList.length + ']';
                                var DFCurrFolder = (new File(DARKinputFolder)).fsName;
                                DFgroup.DFlabel.helpTip = 'Location of files to process:\r' + DFCurrFolder;
                                FolderChecker()
            }}
              } //opens the folder browse UI using you main folder.
          

           

          So the user presses the DFBtn which opens the folder browse UI & then chooses a folder with image files that match the Array.

           

          It doesn't go straight to error now but it also doesn't complete the 'else' part of the main 'if' statement.

           

          The 'DFgroup.DFlabelQ.text' is not being updated & remains blank.

          The 'DFCurrFolder' is updated & displays the folder path correctly.

          The 'DFgroup.DFlabel.helpTip' is not being updated to include the 'var DFCurrFolder'

           

          Any help on these points would be very appreciated.

           

          Regards..,