Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » how to create an IFile in the same IFolder of another IFile?
how to create an IFile in the same IFolder of another IFile? [message #739381] Mon, 17 October 2011 12:11 Go to next message
Leonardo Kenji Shikida is currently offline Leonardo Kenji ShikidaFriend
Messages: 37
Registered: July 2009
Member
Hi

this sounds like a stupid question, actually.

I have an IFile and I want to create another IFile in the same IFolder.

The problem happens when I am trying to get the IFolder of the root project container

suppose that targetFolder is an IContainer returned by my IFile.getParent();

IFolder folder = targetFolder.getFolder(targetFolder.getFullPath());
IFile file = folder.getFile(cdu.getNome()+".another");
InputStream source = new ByteArrayInputStream(baos.toByteArray());
file.create(source, IResource.NONE, null);


does not work, and so

IFolder folder = targetFolder.getFolder(targetFolder.getLocation());

either does not.

what is the correct way to do this?

TIA

Leo K.

Re: how to create an IFile in the same IFolder of another IFile? [message #739407 is a reply to message #739381] Mon, 17 October 2011 12:50 Go to previous message
Leonardo Kenji Shikida is currently offline Leonardo Kenji ShikidaFriend
Messages: 37
Registered: July 2009
Member
this is so funny...

If it´s a root project node, then you have to do something, otherwise, you can do it in a intuitive way Wink

Of course, "getFolder(null)" is not documented...

IPath path = targetFolder.getLocation();
IProject project = targetFolder.getProject();
IFile file = null;
if (path.equals(project.getLocation())){			
	file = project.getFile(cdu.getNome()+".other");
}else{
	IFolder folder = targetFolder.getFolder(null);
	file = folder.getFile(cdu.getNome()+".other");
}
InputStream source = new ByteArrayInputStream(baos.toByteArray());
file.create(source, IResource.NONE, null);


TIA

Leo K.

[Updated on: Mon, 17 October 2011 12:51]

Report message to a moderator

Previous Topic:How to add Internal Web Browser like Safari or Chrome in Eclipse plugin View
Next Topic:Supporting multiple versions of Eclipse
Goto Forum:
  


Current Time: Fri Apr 26 03:20:01 GMT 2024

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

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

Back to the top