Expand my Community achievements bar.

SOLVED

How to fetch /content/dam/ and further folder path in AEM

Avatar

Level 1

 I am fetching userGroups associated with it.
now, i need to generate a hashmap containing :

Client Name vs ArrayList of User Groups

 

 
 
 
Session session = resourceResolver.adaptTo(Session.class);
 
 
 
 
 
 
 
 
 
 
 

Any help through this is welcome.
Thanks.
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Mahima31144209xufe 

As you need to fetch all the folder path and as you said folder means multiple clients, assuming your client's folder will look like this:

AsifChowdhury_1-1690456842694.png

So if we iterate the list of children for the path: "/content/dam/clients", we will get all its child folder paths within the given path.

AsifChowdhury_0-1690456756096.png

 

View solution in original post

5 Replies

Avatar

Community Advisor

Hi @Mahima31144209xufe 

You can resolve the parent path using a resource resolver. Then with that resource, you can get its children, it will be an iterator, and by each of the children, you can get the path.

Here is the code snippet:

 

Resource resource = resourceResolver.getResource("/content/{path}");
Iterator<Resource> resourceIterator = resource.listChildren();
while (resourceIterator.hasNext()){
    String path = resourceIterator.next().getPath();
}

 

NB: You need read permission for the user. and have to identify the folders conditionally.

hi
suppose my folder path is something like:
/content/dam/folders

Avatar

Correct answer by
Community Advisor

Hi @Mahima31144209xufe 

As you need to fetch all the folder path and as you said folder means multiple clients, assuming your client's folder will look like this:

AsifChowdhury_1-1690456842694.png

So if we iterate the list of children for the path: "/content/dam/clients", we will get all its child folder paths within the given path.

AsifChowdhury_0-1690456756096.png

 

thanks
@AsifChowdhury 
its working fine now
actually the path we need to limit it so, that we can get the desired folder structure.
suppose the folder structure is like: /content/dam/client/brands
from here i need to fetch the client names.

anything to do so, that we can have the client names with us