Recursive approach:
public void processChilds(int parentID) {
List childs=selectChilds(parentID);//call method which return list of sub folders of the parameter
for(int i=0;i<childs.size();i++) {
processChilds(childs.get(i));//call processChilds() for each child
}
}
And Implement the selectChilds(int parentID) as your requirement and that must return list of sub folders.