-1

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

2
  • Won't that be horribly horribly slow on big installs? Commented Nov 24, 2016 at 22:27
  • yes i am sure it would be, but we need it for one time analysis Commented Nov 26, 2016 at 12:03

2 Answers 2

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);
    }
    
Sign up to request clarification or add additional context in comments.

2 Comments

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 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
This query only gets the documents. Not the folders
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); 
    }
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.