13 Replies Latest reply on Dec 25, 2014 2:56 PM by Teetan VK

    Script for get titles of subfolders

    Teetan VK Level 1

      Hi everyone,

       

      If a folder full of subfolders, may be thousands.

       

      Is that possible to make a script for get those titles of the subfolders.

       

      Thanks

       

      Teetan

        • 1. Re: Script for get titles of subfolders
          Ronald63 Level 4

          Hi,

           

          Try this snippet ...

          var myFolder=Folder("~/Documents/");
          var subFolderList = new Array;
          
          getSubFolders(myFolder);
          
          function getSubFolders(theFolder) {
               var elementList = theFolder.getFiles();
               for (var i= 0; i< elementList.length;i++) {
                    var aElement = elementList[i];
                    if (aElement instanceof Folder){
                         subFolderList.push(aElement.displayName);
                          //getSubFolders(aFile); // recursive function
                    }
               }
               $.writeln (subFolderList)
          }
          

          I hope this will help you


          Regards

          Ronald

          • 2. Re: Script for get titles of subfolders
            Teetan VK Level 1

            Thanks Ronald

             

            I change the script into like this

             

            var myFolder=Folder("~Desktop\Teetan"); 

            var subFolderList = new Array; 

             

            getSubFolders(myFolder); 

             

            function getSubFolders(theFolder) { 

                 var elementList = theFolder.getFiles(); 

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

                      var aElement = elementList[i]; 

                      if (aElement instanceof Folder){ 

                           subFolderList.push(aElement.displayName); 

                            //getSubFolders(aFile); // recursive function 

                      } 

                 } 

                 $.writeln (subFolderList) 

            }

             

            then run it

            but it seems nothing response to me

            how can make it happen?

             

            Teetan

            • 3. Re: Script for get titles of subfolders
              Ronald63 Level 4

              subFolder's titles are in the array subFolderList.

              If you run the script in ExtendScript Toolkitn, you can see all title's subFolder in the Javascript Console.

               

              That you want to do exactly with subFolder's titles ?

              • 4. Re: Script for get titles of subfolders
                Teetan VK Level 1

                Hi Ronald

                 

                All I got are these:

                 

                Result: undefined

                <![CDATA[

                ]]>Result: undefined

                <![CDATA[

                ]]>Result: undefined

                 

                is that possible to writein in the text file like xxxx.txt?

                 

                Teetan

                • 5. Re: Re: Script for get titles of subfolders
                  Ronald63 Level 4
                  var myFolder=Folder("~/Documents");
                  var subFolderList = new Array;
                  var logFile = new File(myFolder + "/"+"logFile.txt");
                  
                  getSubFolders(myFolder);
                  
                  function getSubFolders(theFolder) {
                       var elementList = theFolder.getFiles();
                       for (var i= 0; i< elementList.length;i++) {
                            var aElement = elementList[i];
                            if (aElement instanceof Folder){
                                 subFolderList.push(aElement.displayName);
                                 writeLogFile(aElement.displayName)
                                  //getSubFolders(aFile); // recursive function
                            }
                       }
                      $.writeln (subFolderList)
                  }
                  
                  function writeLogFile(theString) {
                      logFile.open( "a" );
                      logFile.writeln(theString);
                      logFile.close();   
                  }
                  
                  

                   

                  You are on MacOS or Windows ?

                  • 7. Re: Re: Script for get titles of subfolders
                    pixxxel schubser Level 5

                    Teetan VK schrieb:

                    … All I got are these:

                     

                    Result: undefined

                    <![CDATA[

                    ]]>Result: undefined

                    <![CDATA[

                    ]]>Result: undefined

                     

                    Hi.Teetan VK

                    Your syntax is wrong.

                     

                    replace these lines:

                    var myFolder=Folder("~Desktop\Teetan");
                    var subFolderList = new Array;
                    
                    

                     

                    with this:

                    var myFolder=Folder("~/Desktop/Teetan/");
                    var subFolderList = new Array ();
                    
                    

                     

                     

                    Teetan VK schrieb:

                    … is that possible to writein in the text file like xxxx.txt?

                     

                    var myFile = File("~/Desktop/Some.txt");
                    myFile.open('w');
                    myFile.write(subFolderList);
                    myFile.close();
                    

                     

                    Have fun

                     

                    • 8. Re: Script for get titles of subfolders
                      Teetan VK Level 1

                      Thanks all gus

                       

                      but can you gus me fix this line error?

                       

                                     writeLogFile(aElement.displayName)

                       

                      Teetan

                      • 9. Re: Script for get titles of subfolders
                        Teetan VK Level 1

                        Hi Ronald

                         

                        Is that possible to change this script for get the tltles of the subfolder hierarchy?

                         

                        Thanks

                         

                        Teetan

                        • 10. Re: Script for get titles of subfolders
                          Ronald63 Level 4

                          Hi,

                          What do you mean by "get the tltles of the subfolder hierarchy"?

                           

                          • 11. Re: Script for get titles of subfolders
                            Teetan VK Level 1

                            Hi Ronald

                             

                            in side the subfolders have their own subfolder

                             

                            thank you for your respons

                             

                            thank so much

                             

                            Teetan

                            • 12. Re: Re: Script for get titles of subfolders
                              Ronald63 Level 4

                              Try this ...

                               

                              var myFolder=Folder("~/Documents");
                              var myFolderPath =myFolder.path;
                              var refCountSep = myFolderPath.split("/").length
                              var subFolderList = new Array;
                              var logFile = new File(myFolder + "/"+"logFile.txt");
                              
                              getSubFolders(myFolder);
                              
                              function getSubFolders(theFolder) {
                                   var elementList = theFolder.getFiles();
                                   for (var i= 0; i< elementList.length;i++) {
                                        var aElement = elementList[i];
                                        if (aElement instanceof Folder){
                                             subFolderList.push(aElement.displayName);
                                             countSep = aElement.path.split("/").length
                                             tabCount = countSep - refCountSep
                                             myIndent = Array(tabCount).join('\t')
                                             writeLogFile(myIndent + aElement.displayName)
                                             getSubFolders(aElement); // recursive function
                                        }
                                   }
                                  //$.writeln (subFolderList)
                              }
                              
                              function writeLogFile(theString) {
                                  logFile.open( "a" );
                                  logFile.writeln(theString);
                                  logFile.close();   
                              }
                              
                              
                              • 13. Re: Script for get titles of subfolders
                                Teetan VK Level 1

                                Thank you Ronald

                                 

                                Thank so much

                                 

                                Teetan