Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Get IFile in a project from string
Get IFile in a project from string [message #277979] Mon, 20 December 2004 08:42 Go to next message
Eclipse UserFriend
Originally posted by: mcico.gmx.ch

Hi

I have a question, is there an easy way to get an IFile from a String?
I have the project and search a specific and existing file in it. But
with the getFile() and the findMember() methods i get a handle, which
points to a wrong place.

// example of what i want
IProject project =
ResourcesPlugin.getWorkspace().getRoot().getProject(<projectname >);
IFile file = // now a method to get the file, which might be deeper
down the resource tree than one level

greetings
marco
Re: Get IFile in a project from string [message #278001 is a reply to message #277979] Mon, 20 December 2004 12:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tschlat.gmx.de

Marco Cicolini wrote:

> Hi

> I have a question, is there an easy way to get an IFile from a String?
> I have the project and search a specific and existing file in it. But
> with the getFile() and the findMember() methods i get a handle, which
> points to a wrong place.

> // example of what i want
> IProject project =
> ResourcesPlugin.getWorkspace().getRoot().getProject(<projectname >);
> IFile file = // now a method to get the file, which might be deeper
> down the resource tree than one level

> greetings
> marco

I hope this is what you want. At least it works fine for me:

IProject storageProject = workspace.getRoot().getProject(STORAGE_PROJECT);
try {
// just make sure your project is up to date
storageProject.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e1) {
log.error(e1);
}
IPath path1 = new Path("/client/testclient/test.xml");
IResource resource = storageProject.findMember(path1);
IPath localPath = ((File)resource).getLocation();
// localPath is now "E:/dev/workspace/storage/client/testclient/test.xml"
Re: Get IFile in a project from string [message #278002 is a reply to message #277979] Mon, 20 December 2004 13:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: john.eclipsefaq.org

The answer depends on what your string looks like. Is it a file system
path (like c:\temp\myProject\MyFile.txt)? In this case
IWorkspaceRoot.findFilesForLocation will help. If the path is a
workspace path such as "/Project/Folder/File.txt", then
IWorkspaceRoot.findMember is what you're looking for.
--

Marco Cicolini wrote:
> I have a question, is there an easy way to get an IFile from a String? I
> have the project and search a specific and existing file in it. But with
> the getFile() and the findMember() methods i get a handle, which points
> to a wrong place.
>
> // example of what i want
> IProject project =
> ResourcesPlugin.getWorkspace().getRoot().getProject(<projectname >);
> IFile file = // now a method to get the file, which might be deeper down
> the resource tree than one level
Re: Get IFile in a project from string [message #278097 is a reply to message #278002] Wed, 22 December 2004 02:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mcico.gmx.ch

hi there,

well i was not that exact with my question, the String i use to
finde/get the IFile is only the name of the File, i dont have the Path
or other information about it.

Therefore the proposed solution is not working. For now i search the
whole project for the specific filename....
Re: Get IFile in a project from string [message #278125 is a reply to message #278097] Wed, 22 December 2004 15:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: john.eclipsefaq.org

If you only have the simple file name, then a naive search through the
entire project is the best you can do. Any (and all) directories could
have a file by that name.
--

Marco Cicolini wrote:
> hi there,
>
> well i was not that exact with my question, the String i use to
> finde/get the IFile is only the name of the File, i dont have the Path
> or other information about it.
>
> Therefore the proposed solution is not working. For now i search the
> whole project for the specific filename....
>
Re: Get IFile in a project from string [message #278345 is a reply to message #278125] Wed, 29 December 2004 11:57 Go to previous message
Eclipse UserFriend
Originally posted by: mcico.gmx.ch

On 2004-12-22 21:47:33 +0100, John Arthorne <john@eclipsefaq.org> said:

> If you only have the simple file name, then a naive search through the
> entire project is the best you can do. Any (and all) directories could
> have a file by that name.

yes, thats what i did. i thought, that the api provides such a function.
Previous Topic:Checking out a project from CVS Branch
Next Topic:editor to view (newbie)
Goto Forum:
  


Current Time: Sun Nov 09 20:54:44 EST 2025

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

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

Back to the top