Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to get IFolder of an IProject?
How to get IFolder of an IProject? [message #1458700] Sat, 01 November 2014 18:05 Go to next message
Simon Schäfer is currently offline Simon SchäferFriend
Messages: 14
Registered: June 2011
Junior Member
I have an IProject (or its IPath) but I need an IFolder. I tried to use `project.getFolder("/")` but that results in an exception:

java.lang.IllegalArgumentException: Path must include project and resource name: /projectName


I get the same exception when I use `ResourcesPlugin.getWorkspace().getRoot().getFolder(projectPath)`.

It seems that the API doesn't allow to retrieve an IFolder to an IProject. Is there another way to get an IFolder?

In case anyone wonders why I need this: It is possible to have projects whose source folder is the projects root folder. I have an API that can work with source folders when I pass their corresponding IFolder, therefore I somehow need to create an IFolder object.

Re: How to get IFolder of an IProject? [message #1464539 is a reply to message #1458700] Fri, 07 November 2014 17:22 Go to previous messageGo to next message
Kevin Milburn is currently offline Kevin MilburnFriend
Messages: 1
Registered: November 2014
Junior Member
The easiest way appears to be using the projects location, e.g.
IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(project.getLocation());

However, this relies on the project being within the workspace (which is common, but not required)

As an alternative (and safer approach), both IProject and IFolder extend IContainer; if you modified your API accordingly, you could pass folders, projects and anything else that is IContainer derived (e.g. the workspace root).
Re: How to get IFolder of an IProject? [message #1464674 is a reply to message #1464539] Fri, 07 November 2014 19:48 Go to previous message
Simon Schäfer is currently offline Simon SchäferFriend
Messages: 14
Registered: June 2011
Junior Member
Thanks, this works. And you are right about moving to IContainer; when I have the time I'll do that.
Previous Topic:Show heap status preference in custom preference page
Next Topic:Closing a view creates memory leak
Goto Forum:
  


Current Time: Sat Apr 20 03:26:13 GMT 2024

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

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

Back to the top