Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » IResource from a full path
IResource from a full path [message #321214] Thu, 11 October 2007 10:43 Go to next message
Eclipse UserFriend
Hi All,

I hope this is a really simple question.

If I have a full path to a file and I have an open project, how can I get
the IResource that represents that file within the project?

Thanks,
Mark
Re: IResource from a full path [message #321219 is a reply to message #321214] Thu, 11 October 2007 11:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

IProject.getFile()
Re: IResource from a full path [message #321221 is a reply to message #321219] Thu, 11 October 2007 12:07 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Prakash,

I tried that and I'm not sure that what I get back is correct.

If I have a project that exists at:
C:\MyProjects\Project1

And I have a file string (for a file that does exist) at:
C:\MyProjects\Project1\SomeDirectory\File1.ext.

If I call project.getFile("C:\MyProjects\Project1\SomeDirectory\File1.ext ")
The path of the returned file is not correct, it seems.

It returns:

"Project1/MyProjects/Project1/SomeDirectory/File1.ext"

You can see that the project name is listed twice as well as the directory
name that contains the project.

Am I missing something?

Thanks again,
Mark


"Prakash" <automatic@javalobby.org> wrote in message
news:750847905.3941192117670077.JavaMail.root@cp9.dzone.com...
> IProject.getFile()
Re: IResource from a full path [message #321222 is a reply to message #321221] Thu, 11 October 2007 12:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

the path should be relative to the Project. Not an absolute path.
Re: IResource from a full path [message #321223 is a reply to message #321222] Thu, 11 October 2007 13:00 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Prakash

That goes back to my original question....

If I have a full path, is there a direct way of converting that into a
project relative resource.

Thanks again,
Mark



"Prakash" <automatic@javalobby.org> wrote in message
news:755702387.327101192120362095.JavaMail.root@cp9.dzone.com...
> the path should be relative to the Project. Not an absolute path.
Re: IResource from a full path [message #321226 is a reply to message #321223] Thu, 11 October 2007 13:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Hi,

IFile file =
ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( new
Path("C:\MyProjects\Project1\SomeDirectory\File1.ext"));

The problem with using project.getFile() is that it expects the path to
be relative to the project, but it wasn't. It was relative to the root
of the dis drive.

IWorkspaceRoot.getFileForLocation() expects the path to be relative to
the root of the disk drive.

--
Thanks,
Rich Kulp
Re: IResource from a full path [message #321227 is a reply to message #321226] Thu, 11 October 2007 14:03 Go to previous message
Eclipse UserFriend
Thanks HUGE Rich,

That's exactly what I was looking for.

Mark

"Rich Kulp" <richkulp@us.NO_SPAM.ibm.com> wrote in message
news:felngc$2m5$1@build.eclipse.org...
> Hi,
>
> IFile file =
> ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( new
> Path("C:\MyProjects\Project1\SomeDirectory\File1.ext"));
>
> The problem with using project.getFile() is that it expects the path to be
> relative to the project, but it wasn't. It was relative to the root of the
> dis drive.
>
> IWorkspaceRoot.getFileForLocation() expects the path to be relative to the
> root of the disk drive.
>
> --
> Thanks,
> Rich Kulp
Previous Topic:eclipse-test-framework-3.3 and JUnit4
Next Topic:Removing -consoleLog from Info.plist
Goto Forum:
  


Current Time: Sun May 11 00:11:11 EDT 2025

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

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

Back to the top