3 Replies Latest reply on Nov 11, 2016 11:40 AM by Wosven

    Use getFiles() in an array

    jakec42735283 Level 1

      Hi all,

       

      I'm trying to write a script which searches a folder for packaged files and then searches the links of those files.

       

      I want to store the links and their files separate arrays.

       

      When I put the packaged files in an array I cant seem to use the getFiles() function.

       

      var links = [],
      packaged = [],
      files = [],
      myFolder = Folder( "A:\jake/" ),
      myDocs = [],
      myFiles = myFolder.getFiles(),  //store the target files in a variable
      i;

      for ( i = 0; i < myFiles.length; i++ ) {
         
           if (myFiles[i] instanceof Folder ) {
              
          var links = myFiles[i].getFiles( "Links" )
          packaged.push( links );
            
          }
         
          }

       

      this is a snippet. The packaged array contains all the links folders but when I try and loop through them

       

      for ( i = 0; i < packaged.length; i++ ) {

         

          var y = packaged[i].getFiles()

          links.push( y );

         

          }

       

      This doesn't work.

       

      Any ideas?

        • 1. Re: Use getFiles() in an array
          Jump_Over Level 5

          Hi,

           

          "Links" is not an extension (to filter) but a name of folder (a part of path), so:

           

          var links = Folder(myFiles[i] + "/Links/").getFiles();

           

          jarek

          • 2. Re: Use getFiles() in an array
            jakec42735283 Level 1

            Thanks

             

            I'm using this:

             

            var links = [],
            packaged = [],
            files = [],
            myFolder = Folder( "A:\jake/" ),
            myDocs = [],
            myFiles = myFolder.getFiles(),  //store the target files in a variable
            i;

            for ( i = 0; i < myFiles.length; i++ ) {
               
                 if ( myFiles[i] instanceof Folder ) {
                    
                packaged.push( Folder(myFiles[i] + "/Links/").getFiles() );
                }
               
                }
            for ( i = 0; i < packaged.length; i++ ) {
              
                $.writeln( packaged[i] );
               
                }

             

            But it doesn't seem to pick up all the files (only the first three folders get checked)

            • 3. Re: Use getFiles() in an array
              Wosven Level 1

              Hello,

               

              Perhaps it' s a problem with file or folder's names.

              Your script works fine, but I get empty packaged array when there's no "Links" folder, so iI added : " && Folder(myFiles[i] + "/Links/").exists"

              var links = [],
                  packaged = [],
                  files = [],
                  myFolder = Folder( "A:\jake/" ),
                  myDocs = [],
                  myFiles = myFolder.getFiles();  //store the target files in a variable
              
              for (var i = 0; i < myFiles.length; i++ ) {
              
                  if ( myFiles[i] instanceof Folder && Folder(myFiles[i] + "/Links/").exists) {
                      packaged.push( Folder(myFiles[i] + "/Links/").getFiles() );
                  }
              }
              
              for (var i = 0; i < packaged.length; i++ ) {
                  //alert( packaged[i] );
                  $.writeln( packaged[i] );
              }