John Doe
John Doe

Reputation: 1138

IFile to IResource

How can I get an IResource from an IFile or from an absolute path?

I tried with:

IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
resource = root.findMember(file.getAbsolutePath());

But I get a null value.

Upvotes: 0

Views: 450

Answers (2)

greg-449
greg-449

Reputation: 111142

IFile extends IResource so if you have an IFile you have an IResource.

findMember treats the path it is given as relative to the container (the workspace root in this case). So you can't use it to find a file given an absolute file path - you must use the findFilesForLocation APIs for that.

Upvotes: 2

howlger
howlger

Reputation: 34137

IFile extend IResource, or with other words an IFile is an IResource.

Upvotes: 2

Related Questions