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

cancel
Showing results for 
Search instead for 
Did you mean: 
raju_gonda
Member II

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

can anyone help me in this..

11 Replies
yash_patel_c2
Established Member

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

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

kintu_barot
Senior Member

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

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
raju_gonda
Member II

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

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

raju_gonda
Member II

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

Hi Yash..!!

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

kintu_barot
Senior Member

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

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
raju_gonda
Member II

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

It is giving wrong count Smiley Sad

Can you once check?

kintu_barot
Senior Member

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

It counts 'documentLibrary' folder as well.

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

Regards,

Kintu

ContCentric

Regards,
Kintu
raju_gonda
Member II

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

Hi Kintu Barot,

Thanks for your answer.

if we don't know the how many levels in a particular site, how can we write recursive logic..?

abhinavmishra14
Advanced

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

Similar question was asked earlier: https://community.alfresco.com/message/846309-re-can-anyone-help-me-with-custom-webscript-for-findin...

~Abhinav
(ACSCE, AWS SAA, Azure Admin)