Loop through sub-folders

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Customer

Loop through sub-folders

Jump to solution

Hi,

I want to loop through sub-folders of a certain folder via javascript. My code looks like this:

function processNodes(myNodes) {
	for (i = 0; i < myNodes.length; i++) {
		doSomething(myNodes[i]);
		if (recursive) 
		{
			childNodes = myNodes[i].childFileFolders(false, true);				
			if (childNodes.length) {
				processNodes(childNodes);
			}
		}
	}
}

var referenceType = "node"; 
var reference = ["workspace", "SpacesStore", "e2686b75-7ebf-45a3-8364-7613001c6e14"];
foundNode = search.findNode(referenceType, reference);
nodes = foundNode.childFileFolders(false, true);
processNodes(nodes);

The nodes = foundNode.childFileFolders(false, true); returns two folders. But the function processNodes only handles the first one. I would expect that it also handles the second one because recursive = true. But it does not. What am I doding wrong?

Thanks,

Patrick

1 Solution

Accepted Solutions
Highlighted
Community Manager
Community Manager

Re: Loop through sub-folders

Jump to solution

Hi @patrickvanhoof ,

Have you thought of using a query instead => https://hub.alfresco.com/t5/alfresco-content-services-forum/list-all-folder-subfolders-files-via-web...

This might be more efficient than walking a heavily populated tree?

HTH

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!

View solution in original post

3 Replies
Highlighted
Community Manager
Community Manager

Re: Loop through sub-folders

Jump to solution

Hi @patrickvanhoof ,

Have you thought of using a query instead => https://hub.alfresco.com/t5/alfresco-content-services-forum/list-all-folder-subfolders-files-via-web...

This might be more efficient than walking a heavily populated tree?

HTH

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!

View solution in original post

Highlighted
Customer

Re: Loop through sub-folders

Jump to solution

Hi,

nodes = search.query({
	language: 'fts-alfresco',
	query: 'ANCESTOR:"workspace://SpacesStore/e2686b75-7ebf-45a3-8364-7613001c6e14"',
	maxItems: 2000
});

This indeed works much better/faster.

Thanks.

Patrick

Highlighted
Community Manager
Community Manager

Re: Loop through sub-folders

Jump to solution

Hi @patrickvanhoof,

Thanks for reporting back - and for the code snippet. Will help other people in the same situation.

Are you thinking about attending DevCon 2020Full session speakers get a free ticket!

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!