Recursively list all files in eclipse workspace programmatically

前端 未结 1 1726
挽巷
挽巷 2020-12-03 23:46

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

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

相关标签:
1条回答
  • 2020-12-04 00:49

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

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

    Something like:

    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);
        }
    } 
    
    0 讨论(0)
提交回复
热议问题