Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [pde-dev] IFile.exists() always returns false

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,
you can't coping or creating in your workspace an external file, you
can only link the out file. So, in the following code is an example:

....
IFile file = project.getFile(linkName); //
linkName is the name of resource that will be create into workspace
if (!file.exists()){
file.createLink((new File(fileName)).toURI(),
0, null); // fileName is the full name of the file out of workspace.
}
...
the linked file in the navigator view are shown whit a little arrow
down right. I hope I can help you.

Donald E. Stinchfield wrote:
> Thank you Alessandro. Here is the follow up to your question.
>
> I create the project with the following code:
>
> project=ResourcesPlugin.getWorkspace().getRoot().getProject(
> "myProject"); IProgressMonitor mon = (IProgressMonitor) new
> NullProgressMonitor(); project.create( mon ); project.open ( mon
> );
>
> I save the project so I can easily fetch it with getProject(). I
> always check that the project exists and ensure it is open before I
> continue with the following code.
>
> IProject project = getProject(); if (project.exists() &&
> !project.isOpen()) project.open(null);
>
> I have a method that takes IContainer as a parameter. The purpose
> of the method is to copy files out of a database and into my
> workspace. I call the routine by casting project to IContainer.
> For example,
>
> loadSubtree(source, (IContainer)project);
>
> The problem is in loadSubtree(). Note, just before calling
> loadSubtree() I created the project, verified it exists, and made
> user it is open just before making the call to loadSubtree.
>
> private void loadSubtree (MyDB source, IContainer toContainer ) . .
> .
>
> IPath workspaceIPath = new Path(absolutePathToFile); IFile toFile =
> toContainer.getFile(workspaceIPath);
> toFile.refreshLocal(IResource.DEPTH_INFINITE, null); if
> (toFile.exists()) toFile.setPersistentProperty(MY_KEY, "Some
> string"); . . .
>
> I'm sure I have the correct project. If I let the code run I see
> the project in navigator loaded with all the files I put in the
> workspace. The problem is toFile.exists() always returns false so
> I'm never able to set a persistent property on my file. I must be
> doing something wrong.
>
>
>> -----Original Message----- From: pde-dev-bounces@xxxxxxxxxxx
>> [mailto:pde-dev-bounces@xxxxxxxxxxx] On Behalf Of Alessandro
>> Assab Sent: Wednesday, January 17, 2007 5:42 AM To: Eclipse PDE
>> general developers list. Subject: Re: [pde-dev] IFile.exists()
>> always returns false
>>
> Donald E. Stinchfield wrote:
>>>> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal,
>>>> div.MsoNormal {margin:0in; margin-bottom:.0001pt;
>>>> font-size:12.0pt; font-family:"Times New Roman";} a:link,
>>>> span.MsoHyperlink {color:blue; text-decoration:underline;}
>>>> a:visited, span.MsoHyperlinkFollowed {color:purple;
>>>> text-decoration:underline;} span.EmailStyle17
>>>> {mso-style-type:personal-compose; font-family:Arial;
>>>> color:windowtext;} @page Section1 {size:8.5in 11.0in;
>>>> margin:1.0in 1.25in 1.0in 1.25in;} div.Section1
>>>> {page:Section1;} -->
>>>>
>>>> From my plugin code I have created a new file in my workspace
>>>> and am adding it to my project using the following code:
>>>>
>>>>
>>>>
>>>> IPath workspaceIPath = *new* Path(absolutePathToFile);
>>>>
>>>> IFile toFile =
> toContainer.getFile(workspaceIPath);
>>>>
> What's return *toContainer*? If the last method return the
> *project* in which the file exist, are you sure that it's the
> correct project? The following code is an example to my
> implementation.
>
> IWorkspace workspace = ResourcesPlugin.getWorkspace();
> IWorkspaceRoot root = workspace.getRoot(); if
> (root.getProjects()!=null && root.getProjects().length>0) { // for
> (int i=0; i<root.getProjects().length;i++) { // try { if
> (root.getProjects()[i].isOpen()) {
> root.getProjects()[i].open(null); }
> root.getProjects()[i].getFile(...); } catch (CoreException e) { //
> TODO Auto-generated catch block e.printStackTrace(); //
> } } }
>>>>
>>>>
>>>> I don't bother calling toFile.create() since the file is
>>>> already there, plus from the navigator I see my new file in
>>>> the project. All looks good so far.
>>>>
>>>>
>>>>
>>>> The problem is I want to set a property value on the file as
>>>> soon as I add it to the workspace. I'm using the following
>>>> updated code
>>>>
>>>>
>>>>
>>>> IPath workspaceIPath = *new* Path(absolutePathToFile);
>>>>
>>>> IFile toFile =
> toContainer.getFile(workspaceIPath);
>>>>
>>>> toFile.refreshLocal(IResource./DEPTH_INFINITE/, *null*);
>>>>
>>>> *if* (toFile.exists())
>>>>
>>>> toFile.setPersistentProperty(/MY_KEY/, "Some string");
>>>>
>>>>
>>>>
>>>> toFile.exists() always returns false. I thought
>>>> refreshLocal() would take care of it, but it doesn't. I've
>>>> tried a bunch of things and have searched through the bug
>>>> list and mailing lists. I haven't come up with anything.
>>>> Any thoughts?
>>>>
>>>>
>>>>
>>>> Regards,
>>>>
>>>> Don
>>>>
>>>>
>>>>
>>>> * *
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
> ----------------------------------------------------------------------
>
>>>>
>>>> _______________________________________________ pde-dev
>>>> mailing list pde-dev@xxxxxxxxxxx
>>>> https://dev.eclipse.org/mailman/listinfo/pde-dev
>>
_______________________________________________
pde-dev mailing list
pde-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/pde-dev

> _______________________________________________ pde-dev mailing
> list pde-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/pde-dev

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org

iD8DBQFFrjPaJDRPjKlSMUYRAraKAJwKQFwjC0kijwZ2bTz6JJhTDFPWngCcDB1L
bYaiVeDBgV/KTTVm+IJPzJA=
=g/0d
-----END PGP SIGNATURE-----



Back to the top