Can anyone help me with custom webscript for finding the number of folders and sub-folders present in a given site?

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member

Can anyone help me with custom webscript for finding the number of folders and sub-folders present in a given site?

Json response is preferred.

please include the url path for giving in xml also.

1 Reply
Highlighted
Moderator
Moderator

Re: Can anyone help me with custom webscript for finding the number of folders and sub-folders present in a given site?

You can create a custom Javascript or java backed web-script to get the list of folders and subfolders. 

Execute a search query from your custom webscript to list the folders and subfolders and write to a json object and return in response. 

If you want to get all folders at any depth then, Search query would be something like this:

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

Get the count from returned result set and to get the path for each returned nodeRefs use 'nodeService.getPath(nodeRef).toDisplayPath(nodeService, permissionService)'

If you want to get all folders at first level and then get subfolders for each folder then, Search query would be something like this:

1 Pass: PATH:"/app:company_home/st:sites/cm:test-site/cm:documentLibrary/*" AND TYPE:"cm:folder"

2 Pass: 

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

3 Pass: 

PATH:"/app:company_home/st:sites/cm:test-site/cm:documentLibrary/cm:MyFolder/cm:MySubFolder/*" AND TYPE:"cm:folder"

And so on.. depending on levels of subfolders. 

Get the folders and subfolders recursively and prepare a POJO having parent and child count including the display path and convert it to JSON at the end when all folders/sub-folders are iterated. 

Refer here on how to write custom webscripts: https://ecmarchitect.com/alfresco-developer-series-tutorials/webscripts/tutorial/tutorial.html 

You can find sample source code here: https://github.com/jpotts/alfresco-developer-series/tree/master/webscripts/webscripts-tutorial

There is a question by someone else on the same lines, this may be helpful to you as well: https://community.alfresco.com/thread/233943-list-all-folder-subfolders-files-via-webscript

~Abhinav
(ACSCE, AWS SAA-C02)
https://javaworld-abhinav.blogspot.com