cancel
Showing results for 
Search instead for 
Did you mean: 

How to find how many folders are present in a site and path of each folder ?

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

Can someone please help in this?

1 REPLY 1

abhinavmishra14
World-Class Innovator
World-Class Innovator

I think you want to know the numbers if i understand correctly.

You can implement javabacked webscript which can execute a search query to find the folders in a given site at any depth. You can implement same thing using javascript as well.

Sample search query : PATH:"/app:company_home/st:sites/cm:test-site/cm:documentLibrary//*" AND TYPE:"cm:folder"

You can execute the above query in node browser as well and see the total results. 

See the sample code below which can be used to get the number of nodes in a site 

main();

function main(){
//Defualt to cm:folder if no inputs provided
var objectType = (args["objectType"]==null || args["objectType"]==undefined) ? "cm:folder" : args["objectType"];

//Defualt to test-site if no inputs provided
var siteShortName = (args["siteShortName"]==null || args["siteShortName"]==undefined) ? "test-site" : args["siteShortName"];

//Defualt to 0 if no inputs provided
var skipCount = (args["skipCount"]==null || args["skipCount"]==undefined)?0:args["skipCount"];

//Defualt to 1000 if no inputs provided
var maxCount = (args["maxCount"]==null || args["maxCount"]==undefined)?1000:args["maxCount"];

var query = 'PATH:"/app:company_home/st:sites/cm:' +siteShortName+'/cm:documentLibrary//*" AND TYPE:"'+objectType+'"';
var page = {
skipCount : parseInt(skipCount),
maxItems : parseInt(maxCount)
};

var searchQuery = {
query : query,
language : "lucene",
page : page
};

logger.log("Executing SearchQuery: "+query)
var nodes = search.query(searchQuery);
var totalNodes = nodes.length;
logger.log("Total Nodes: "+totalNodes)

model.totalCount = totalNodes;
}
~Abhinav
(ACSCE, AWS SAA, Azure Admin)