2

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.

2 Answers 2

3

You can use the following construction:

ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(URIUtil.toURI(fileName)); 

where fileName - absolute path of File.getAbsolutePath()

and URIUtil from org.eclipse.core.filesystem

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, just wondering why it won't find all IResources like that in general and not just the IFiles.
0

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 Retrieve a file from within a folder in the workspace

2 Comments

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.