Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » load an IResource from a project relative path
load an IResource from a project relative path [message #319191] Tue, 14 August 2007 15:36 Go to next message
Eclipse UserFriend
Originally posted by: dkrebs.tibco.com

Hi,
I have a path to a resource in my workspace that is relative to a specific
project, does anyone know how I can load the IResource from that path
without having to know what project contains the path? For example say in
project a there is a path to file/myfile.txt and using that path I want to
get the IResource, do I have to modify the path to first include the
project name in order to load the IResource or is there an easier way of
doing this? Thanks - Duncan
Re: load an IResource from a project relative path [message #319192 is a reply to message #319191] Tue, 14 August 2007 16:32 Go to previous messageGo to next message
Eclipse UserFriend
Duncan,

If you are sure that your relative path is unique for all the projects
in your workspace then this will do the trick.

IProject[] projects =
ResourcesPlugin.getWorkspace().getRoot().getProjects();

for (IProject p : projects) {
IResource res = p.findMember("file/myfile.txt");

if (res != null) {
// Do my thing
}
}

If there is a potential chance that another project might also contain
the same file you will need to specify the project name. If you specify
the project, you can use

IResource resource =
ResourcesPlugin.getWorkspace().getRoot().findMember("MyProject/file/myfile.txt ");


Hope that helps.

-tanmay

Duncan Krebs wrote:
> Hi, I have a path to a resource in my workspace that is relative to a
> specific project, does anyone know how I can load the IResource from
> that path without having to know what project contains the path? For
> example say in project a there is a path to file/myfile.txt and using
> that path I want to get the IResource, do I have to modify the path to
> first include the project name in order to load the IResource or is
> there an easier way of doing this? Thanks - Duncan
>
Re: load an IResource from a project relative path [message #319193 is a reply to message #319191] Tue, 14 August 2007 16:46 Go to previous message
Eclipse UserFriend
Duncan Krebs wrote:
> Hi, I have a path to a resource in my workspace that is relative to a
> specific project, does anyone know how I can load the IResource from
> that path without having to know what project contains the path? For
> example say in project a there is a path to file/myfile.txt and using
> that path I want to get the IResource, do I have to modify the path to
> first include the project name in order to load the IResource or is
> there an easier way of doing this? Thanks - Duncan

I think you have to know what project it's coming from. It would not be
uncommon at all for two or more projects to have the same file with the
same name and path. Just think of a project's .project file, for
instance. ;) I don't see how it would be possible for an application to
know which file you're referring to otherwise.
Previous Topic:Using ECF creating new projects fails in Eclipse 3.3
Next Topic:SafeRunnable and ListenerList remove of listener on Exception
Goto Forum:
  


Current Time: Tue Jul 22 08:32:21 EDT 2025

Powered by FUDForum. Page generated in 0.26995 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top