Search code examples
eclipseeclipse-rcpeclipse-plugin

Recursively list all files in eclipse workspace programmatically


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

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


Solution

  • 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);
        }
    }