-1

Need a js based alfresco webscript to get the list of all folders and files recursively alond with their size.

user3331349
  • 49
  • 1
  • 7

2 Answers2

3

CMIS Query:

select cmis:objectId, cmis:name, cmis:contentStreamLength 
from cmis:document 
where cmis:contentStreamLength>0 
order by cmis:contentStreamLength desc
  • HTTP GET:

    http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser/
      ?cmisselector=query
      &succinct=true
      &q=select cmis:objectId, cmis:name, cmis:contentStreamLength from cmis:document where cmis:contentStreamLength>0 order by cmis:contentStreamLength desc
    
  • JavaScript:

    Use search root object:

    search - org.alfresco.repo.jscript.Search - Root object providing access to the various Alfresco search interfaces such as FTS-Alfresco, Lucene, XPath, and Saved Search results

    var rs=search.query({
        query:"select * from cmis:document where cmis:contentStreamLength>0 order by cmis:contentStreamLength desc",
        language:"cmis-alfresco"         
    });
    
    for (var r in rs){
        logger.log(rs[r].parent.nodeRef.id+"/"+rs[r].nodeRef.id+"\t"+rs[r].parent.name+"/"+rs[r].name+"\t"+rs[r].size);
    }
    
kinjelom
  • 6,105
  • 3
  • 35
  • 61
  • Thanks for your answer :) but i am a beginner in alfresco webscripting and have no idea how to execute this. i have explored some tutorials on alfresco like http://docs.alfresco.com/4.1/concepts/ws-folderListing-intro.html which involve :- 1. a js file 2. a free marker template 3. a descriptor xml file we create and register these in alfresco and hit through url and get the things. Is it possible to have my question solved by such a solution ? Thanks – user3331349 Nov 26 '16 at 12:01
  • This query only gets the documents. Not the folders – MonkeyDreamzzz Feb 23 '18 at 08:07
1

Yes it is possible. you can get the all folders,subfolders,and all the files using repository javascript Please try this code give proper path values

var path="Data Dictionary/***";
var documentLibrary = companyhome.childByNamePath("path");

var children = documentLibrary.children;

traverse(children);

function traverse(nodes){
  for each(var node in nodes) {
    if (node.isContainer){
      logger.log(node.name + " is a folder, traversing down");
      traverse(node.children);
    }else {
      logger.log(node.name ); 
        logger.log(node.size); 
    }
  }
}
Vikash Patel
  • 1,328
  • 9
  • 28