3 Replies Latest reply on Jul 8, 2016 8:45 AM by Peter Kahrel

    Array.Push() Only Adding First Few Rows

    WilliamsCh

      Afternoon,

       

      I am troubleshooting/supporting an in-house script for InDesign. What the script is designed to do is: We feed in a quote-delimited text file generated by an internal process. The script iterates through that, splits the lines as needed, adds them to an array, and populates a pre-existing template based on the contents.

       

      However, for some reason, the Array.Push function that actually adds the split lines into the overall array isn't working properly. It adds up to twenty records, and then the rest just... disappear. Nothing's deleted, nothing's overwritten - but the first twenty records of a ~1000 record long file are the only ones that get picked up, and I'm not sure why. (To clarify: The loop goes through the whole file, and the Array.Push is successfully called on each iteration. It just doesn't seem to do anything, and the try/catch never fires.)

       

      Any help would be very useful. There's more code than I've provided, and I can share it if need be, but this is the salient function.

       

      function readDelimitedFile ( fPath, delimiter ) {
      
      
        var returnArray = new Array();
        var dataNames = new Array();
      
      
        var fileObject = File ( fPath ) ;
        if ( ! fileObject.exists ) {
          return returnArray ;
        }
      
      
        var escapedDelimiter = slashEscape(delimiter);
        var tabExpression = new RegExp ( escapedDelimiter ) ;
      
      
        try {
          fileObject.open ('r') ; //-- Open for reading.
          
          while ( ! fileObject.eof ) {
            var currentLine = fileObject.readln () ;
            if ( tabExpression.test( currentLine ) ) {
              var lineData = currentLine.split (delimiter);
              returnArray.push(lineData) ;        
            }
          }
      
      
          fileObject.close() ;
        }
      
      
        catch (errMain) {
          try {
            fileObject.close() ;
          }
          catch (errInner ) { }
        }
        return (returnArray);
      }