4 Replies Latest reply on Feb 21, 2014 7:03 AM by Unique

    Find folder name in integer

    Unique Level 1

      Hi,

       

      I need a help to find the indesign files within the folder(s) path and get alert if they the file name is matching.

       

      While most of the folder name is commong (highlighted in blue) and only one folder name (highlighted in red) will vary.

       

      eg.,

       

      name = Folder("/Users/TTT/Desktop/PRODUCTION/Tag_London/B/BB/BEAS/EMEA/CREATIVE_PACKSHOT/909009_/DOCUMENT/").getFiles("*.indd");

      nameT = Folder("/CREATIVE/CHST/WATCHED_FOLDER/BTS/INDesign_IN/").getFiles("*.indd");

       

       

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

      for(j=0; j<nameT.length; j++) {

          if (name[i].parent.parent.parent.parent.parent.parent.name == "BB" )

             

          if(name[i].name.split(".")[0] == nameT[j].name.split(".")[0]) {

              alert (name[i].parent.parent.parent.name)

              }

          else

          alert ("no")

          }}

       

       

      The final destination folder DOCUMENT will be common.

      How can i assign /[0-9]+"_"/ instead of folder 909009_

       

       

      i.e.

      name = Folder("/Users/TTT/Desktop/PRODUCTION/Tag_London/B/BB/BEAS/EMEA/CREATIVE_PACKSHOT/[0-9]+[0-9]+[0-9]+[0-9]+[0-9]+[0-9]+"_"/DOCUMENT/").getFiles("*.indd");

       

      Many thanks for the support.


        • 1. Re: Find folder name in integer
          Loic.Aigon Adobe Community Professional

          Hi,

           

          I don't think you can set a folder reference with dynamic urls (regexp). I think you may want to work in two steps:

           

          1) reference the static parent folder

          var fo = Folder("/Users/TTT/Desktop/PRODUCTION/Tag_London/B/BB/BEAS/EMEA/CREAT IVE_PACKSHOT/");

           

          2) get all "files" and filter folders above files.


          var filterFunction = function(file)
                                        {
          
                                                  return (file instanceof Folder) && /[0-9]+"_"/.test ( file.name ) && Folder ( file+"/DOCUMENT/").exists;
                                        }
          
          var fos = fo.getFiles( filterFunction );
          
          

           

           

          3) Once you have all your folders, populate an array with all internal indd files

           

          var indds = [];
          var n = fos.length;
          var inddFilterFunction = function(file){
               return (file instanceof File) && /\.indd$/.test ( file.name);
          }
          while(n--) {
           indds.concat ( Folder(fos[n]+"/DOCUMENT/").getFiles(inddFilterFunction) );
          }
          

           

           

          4) do whatever you have to do with your array of files

           

          HTH

           

          Loic

          • 2. Re: Find folder name in integer
            pixxxel schubser Level 5

            Hi Unique,

            You can check if the folder name is valid.

             

            searchString = /[0-9]+_/g;
            nameString = "/Users/TTT/Desktop/PRODUCTION/Tag_London/B/BB/BEAS/EMEA/CREATIVE_PACKS HOT/909009_/DOCUMENT/";
            find = nameString.match (searchString);
            if (find) {
            // alert(find)
            // or do something else
            }
            

             

            Have fun

             

            • 3. Re: Find folder name in integer
              Marc Autret Level 4

              My two pennies:

               

              // Your settings
              // ---
              const SUFX = "*.indd",
                    PATH_1 = "/Users/TTT/Desktop/PRODUCTION/Tag_London/B/BB/BEAS/EMEA/CREATIVE_PACKS HOT",
                    RE_1 = /^[\d]{6}_$/,
                    SUB_1 = "/DOCUMENT",
                    PATH_2 = "/CREATIVE/CHST/WATCHED_FOLDER/BTS/INDesign_IN";
              
              // Helpers
              // ---
              File.prototype.shortName = function(){ return this.name.split('.')[0] };
              const PUSH = Array.prototype.push;
              
              // Vars
              // ---
              var a, i, t,
                  ff1,    // array of File objs found in place 1
                  ff2;    // associative array of File names found in place 2
              
              // Feed ff1
              // ---
              for( ff1=[], a=Folder(PATH_1).getFiles(function(x){return x instanceof Folder;}), i=a.length ;
                   i-- ;
                   RE_1.test(a[i].name) && (t=Folder(a[i]+SUB_1)).exists && PUSH.apply(ff1,t.getFiles(SUFX)) );
              
              // Feed ff2
              // ---
              for( ff2={}, a=Folder(PATH_2).getFiles(SUFX), i=a.length ;
                   i-- ;
                   ff2[a[i].shortName()]=0 );
              
              // Check matches
              // ---
              for( i=ff1.length ;
                   i-- ;
                   (t=ff1[i].shortName()) && ff2[t]=ff2.hasOwnProperty(t)?(ff2[t]+((0<=ff2[t])||-1)):-1 );
              
              // Display results
              // ---
              i = (a=["","SRC    DST    DOC","============"]).length;
              for( t in ff2 ) a[i++] = localize("  %1       %2       %3", Math.abs(ff2[t]),+(0<=ff2[t]),t);
              alert( a.join('\r') );
              

               

              @+

              Marc

              • 4. Re: Find folder name in integer
                Unique Level 1

                Thanks so much for the support Loic_agion.

                 

                Thanks so much and much to Marc Autret.