tags:

views:

19

answers:

1

How can i find a Resource with a locationURI?

Path path = new Path('/home/foo/eclipse/runtime-EclipseApplication/someproj/B.txt');
IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(path);

I know there is a way by using the locationURI from current project to trim the "needless" part, but is there a "better" way to slove this issue.

A: 

You can use a FileLocator to find the file within your bundle, if that is what you want (instead of finding a file in the runtime workspace), see http://stackoverflow.com/questions/2148821/retrieve-a-file-from-within-a-folder-in-the-workspace/2150890#2150890

Fabian Steeg
That is not exactly what i wanted. What i have is a absolute OS path to a resource of a current eclipse project. So what i want is to find the IResource with a absolute OS path. Currently i get null from the findMember method, cause it expects a path where the workspace is handled as the root path. In my case it would be /someproj/B.txt. But what i have is /home/foo/eclipse/runtime-EclipseApplication/someproj/B.txt
@user427678 I see - wouldn't know any other way but the solution you mentioned: trimming the path based on the workspace location.
Fabian Steeg
okay. thx anyway!