As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
Json response is preferred.
please include the url path for giving in xml also.
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