How to get absolute path to project files in eclipse using plugin

I am trying to create a plugin that will give me a list of the absolute path of all files inside a project opened in eclipse.

I tried, but I can only get the path to the active window.

My action code:

  IWorkbenchPart workbenchPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart(); 
    IFile file = (IFile) workbenchPart.getSite().getPage().getActiveEditor().getEditorInput().getAdapter(IFile.class);
    if (file == null)
        try {
            throw new FileNotFoundException();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    String path = file.getRawLocation().toOSString();
    System.out.println("path: " + path);

Here I get only the path to the active window. But I need a list of the absolute path for all files inside the project ... only the files in the src folder ...

Please guide me if I can do it the same way or if I need to use several APIs for this.

+5
source share
1 answer

After my research, which I found out below, the code will get the path to the project directory of the current Eclipse workspace:

//get object which represents the workspace  
IWorkspace workspace = ResourcesPlugin.getWorkspace();  

//get location of workspace (java.io.File)  
File workspaceDirectory = workspace.getRoot().getLocation().toFile()

. org.eclipse.core.resources org.eclipse.core.runtime, API

+6

All Articles