1 Reply Latest reply on Apr 3, 2016 11:10 PM by b91823603

    [JS] How to get folder count?

    K159 Level 1

      Hi.

       

      I want to get a number of folders for a specific directory.

       

       

       

       

      var folderCount = Folder("C:/test/file/").getFiles( ? );    // Is this what values need?

      alert(folderCount.length);

       

       

       

       

      If this method is wrong, please tell me the other way.

       

      Thanks

        • 1. Re: [JS] How to get folder count?
          b91823603 Level 3

          Hi,

           

          Get all files from folder and then check whether it is a file or folder. Try this one

           

          var myFileList = Folder("D:/Test").getFiles();

          var folderCount = GetFoldersCount(myFileList) ;

          $.writeln(folderCount);

           

          function GetFoldersCount(fileList)

          {     

              var folderCount = 0;

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

              { 

                  var myFile = myFileList[i]; 

                  if (myFile instanceof Folder) 

                      folderCount++;

              } 

              return folderCount