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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2019 02:48 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2019 04:00 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2019 06:08 AM
Hi Yash..!!
I have no idea about lucene search can tell me the alternate way for getting folders and sub folders
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2019 01:47 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2019 01:50 AM
Thanks for the clarification!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2019 04:40 AM
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
Kintu

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2019 04:54 AM
I don't know javascript, can you pls give me the code with recursive logic and also give me the URL pattern for this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2019 07:17 AM
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
Kintu

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2019 08:32 AM
It is giving wrong count
Can you once check?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2019 08:46 AM
It counts 'documentLibrary' folder as well.
And it is for two levels only, you can use it recursively.
Regards,
Kintu
Kintu
