How to find how many folders and documents are present in a site?

Showing results for 
Search instead for 
Did you mean: 

Re: How to find how many folders and documents are present in a site?

Create a javascript of java backed webscript. Write search query that will take siteshortname and object type (your custom content type, custom folder type, cm:content, cm:folder etc.) and performs a search and returns the count. 

There is a high level code which you can implement in your java backed webscript:


   Query would be something like: 	  
   String countQuery = 'PATH:"/app:company_home/st:sites/cm:' + search.ISO9075Encode(siteShortName) + '//*" AND TYPE:"'+type+'"';
   Where siteShortName and type you will pass for getting the related results.
   You will below sample method to get the count and use it whereever you want:
   long countResult = getObjectCount(countQuery);

	public long getObjectCount(String query) {
		SearchParameters searchParameters = new SearchParameters();
		ResultSet results = null;
		long objectCount = 0;
		try {
			results = searchService.query(searchParameters);
			if (null != results) {
				objectCount = results.getNumberFound();
		} catch (AlfrescoRuntimeException alfException) {
			LOGGER.error(alfException.getMessage(), alfException);
		} finally {
			if (results != null) {
		return objectCount;



For javascript you can refer below sample and customize as per your need:



<shortname>Count Files/folder</shortname>
Counts Objects of given type

Parameter name : {type}
Example : custom:contentType, cm:content, cm:folder etc.

Parameter name : {siteShortName}
Example : test-site
function main(){

	var siteCount = [];
	var type = args["type"];
	var siteShortName = args["siteShortName"];
	var skipCount = (args["skipCount"]==null || args["skipCount"]==undefined)?0:args["skipCount"];
	var maxCount = (args["maxCount"]==null || args["maxCount"]==undefined)?100000:args["maxCount"];
      var countQuery = 'PATH:"/app:company_home/st:sites/cm:' + search.ISO9075Encode(siteShortName) + '//*" AND TYPE:"'+type+'"';
      logger.log("CountQuery: "+countQuery);
      var page = {
			skipCount : parseInt(skipCount),
			maxItems : parseInt(maxCount)
      var searchQuery = {
		  query : countQuery,
		  language : "lucene",
		  page : page
	  var nodes = search.query(searchQuery);      
      var nodeCount = nodes.length;
	  siteCount[siteShortName] = nodeCount;	




<title>Count of a given type</title>
<h4>Count of the given objects</h4>
<b>Count Query:</b> <#if query??>${query}<#else>-</#if><br/>
<#if siteCount?is_hash_ex>
<table border="1">
<th align="center">Site Short Name</th>
<th align="center">Count</th>
<#assign keys = siteCount ?keys>
<#list keys as key>
<td align="center">${key}</td>
<td align="center">${siteCount [key]}</td>


Active Member

Re: How to find how many folders and documents are present in a site?

Thank you for the revert.

I was able to count records in a datalist with this approach(Java backed code). 

I also wanted to calculate total size of the datalist in terms of MB/GB(based on amount of records present). What are the possible methods which will return this result. Also, for document library how can I caculate the total number of files and folder count alongwith total size of documentlibrary present using java code. (required for a timer job)