我是露天的新手。我需要将文件夹循环到各个文件夹中包含的子文件夹和文件,以便对父文件夹执行的操作也必须显示在子文件夹上。必须递归调用该方法,但我不知道如何继续进一步。
请在这方面指导我。谢谢..
最佳答案
在我看来,您在理解如何为文件夹创建递归操作方面遇到了问题。我将尝试给你一个例子来说明我将如何处理这个问题。鉴于我的例子可能不是最好的。
public static final String NAME = "Demo-Folder";
public static final String PARAM_ASPECT_NAME = "folder-name";
private NodeService nodeService;
/**
* Set the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void executeImpl(Action action, NodeRef actionUponNodeRef)
{
ChildAssociationRef childAssociationRef = nodeService.getPrimaryParent(actionUponNodeRef);
System.out.println("****The folder is***** "+ childAssociationRef);
iterateThroughChildren(childAssociationRef);
}
public void iterateThroughChildren(ChildAssociationRef childAssocRef)
{
System.out.println("****The folder is***** "+ childAssocRef);
NodeRef childNodeRef = childAssocRef.getChildRef();
List<ChildAssociationRef> children = nodeService.getChildAssocs(childNodeRef);
for (ChildAssociationRef childAssoc : children)
{
childAssoc.getChildRef();
// Use childNodeRef here.
System.out.println("******Documents inside are******"+ childAssoc);
// This call recurses the method with the new child.
iterateThroughChildren(childAssoc);
// If there are no children then the list will be empty and so this will be skipped.
}
}
我使用了上面的代码,并将其扩展为包含一个名为 iterateThroughChildren
的新方法,该方法采用 ChildAssociationRef
并获取子项并迭代它们。在迭代期间,子级将被传回到方法中,以允许迭代其子级,依此类推,直到没有子级(这意味着您位于分支的末尾)。这允许您迭代整个树结构。
关于java - 如何在露天查找文件夹然后子文件夹然后打印文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38198959/