以编程方式递归列出 Eclipse 工作区中的所有文件

2022-01-16 00:00:00 eclipse-plugin eclipse eclipse-rcp

我通过调用 ResourcesPlugin.getWorkspace().getRoot() 来获取工作空间.

I am getting workspace by calling ResourcesPlugin.getWorkspace().getRoot().

如何在工作区中递归列出所有文件(IFile).

How I can list all files(IFile) recursively in the workspace.

推荐答案

工作空间中的根、项目和文件夹都实现了IContainer接口.

The root, projects and folders in a workspace all implement the IContainer interface.

调用IContainer.members()获取容器中的所有资源.

Call IContainer.members() to get all the resources in the container.

类似:

void processContainer(IContainer container) throws CoreException
{
   IResource [] members = container.members();
   for (IResource member : members)
    {
       if (member instanceof IContainer)
         processContainer((IContainer)member);
       else if (member instanceof IFile)
         processFile((IFile)member);
    }
} 

相关文章