cancel
Showing results for 
Search instead for 
Did you mean: 

How to get how many folders and sub folders are present in a site ?

raju_gonda
Champ in-the-making
Champ in-the-making

can anyone help me in this..

11 REPLIES 11

yash_patel_c2
Star Contributor
Star Contributor

Hi,

You can use lucene search for searching all the content of type cm:folder for that particular site and then just get the length of the result.

var result = lucene.search("-----Your Query----");

var a = result.length;

Thanks,

Yash

Hi Yash..!!

I have no idea about lucene search can tell me the alternate way for getting folders and sub folders

afaust
Legendary Innovator
Legendary Innovator

Please, never recommend using the luceneSearch operation. That operation is a legacy holdover from Alfresco 2.x/3.x. Lucene is no longer the primary search language, and since Alfresco 4.x has not received any of the various performance improvements that have been accorded to FTS / CMIS. Ideally, only ever use the generic query() operation and specifically use the "fts-alfresco" or "cmis-strict"/"cmis-alfresco" query languages.

Thanks for the clarification!

kintu_barot
Star Collaborator
Star Collaborator

You can use the following javascript code and execute it in a recursive way.

var site = companyhome.childByNamePath("Sites/<site-name>/documentLibrary");
var count = site.children.length;

The above code will give you the number of children present in documentLibrary.

You can use the same to get the subfolders.

Regards,

Kintu

ContCentric

Regards,
Kintu

I don't know javascript, can you pls give me the code with recursive logic and also give me the URL pattern for this

Use the following code:

var site = companyhome.childByNamePath("Sites/test/documentLibrary");
var children = site.children;
var numberOfChildren = site.children.length;
var count = 0;

for (var index = 0; index < numberOfChildren; index++) {
      if(children[index].isContainer){
          c = children[index].children.length;
          count = count + c + 1;
      } else {
          //uncomment following line if you want to count the document as well
          //count = count +1;
      }
}
logger.log(count);

I hope you know where to use it.

Note: replace the 'test' with your site name.

Regards,

Kintu

ContCentric

Regards,
Kintu

It is giving wrong count Smiley Sad

Can you once check?

It counts 'documentLibrary' folder as well.

And it is for two levels only, you can use it recursively.

Regards,

Kintu

ContCentric

Regards,
Kintu