how to get all assets from a folder under content dam folder in aem



Hi All,


I'm new to AEM please let me know if anyone has idea on below scenario.

I'm working on dam assets -  I would like to delete assets from one particular folder after some specific time So Im using scheduler for this requirement,  but wanted to know how to get all assets from a folder So that once i get list of assets from folder will try to read the jcr:data of all assets like modified date and based on that will delete the asset once it completes some time in dam.


please suggest if approach is not correct


path will be something like this :-  /content/dam/folder


Thanks in advance

Answers (2)

Answers (2)




Hello @sams16001423 

You can utilise the JCR API. The JCR API allows you to query nodes in the JCR with the "JCR_SQL2 search queries". I have provided an example for you below where we are querying for all JCR node-type [dam:AssetContent] under the path "/content/dam/my-project". If results are returned, then we will print each jcr:lastModified (the dam:AssetContent node composes of the jcr:lastModified values). Making a query like this is awesome because you don't need to worry about nested folders.

JCR API - JCR_SQL2 Example Search in the Backend:


private void doExampleSearch(ResourceResolver resolver) throws RepositoryException {
    Session session = resolver.adaptTo(Session.class);
    QueryManager queryManager = session.getWorkspace().getQueryManager();
    String selectQuery = "SELECT * FROM [dam:AssetContent] WHERE ISDESCENDANTNODE ([/content/dam/my-project])";
    Query query = queryManager.createQuery(selectQuery, Query.JCR_SQL2);
    QueryResult queryResults = query.execute();
    if (queryResults != null) {
        NodeIterator resultNodes = queryResults.getNodes();
        while (resultNodes.hasNext()) {
            Node node = resultNodes.nextNode();


 Before the implementation code, you should familiarize yourself with JCR_SQL2 queries. You can test your queries directly from http://localhost:4502/crx/de/index.jsp; tools (drop-down menu item) > query. A tutorial for JCR_SQL2 query language for beginners can be found here:
I hope this helps.




Use Query Builder API to search for all the assets under a folder.