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

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

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

iD8DBQFFrf1iJDRPjKlSMUYRAs2kAKCeSPQal35QZeu1dGRkpczOcAYHVACghFva
2sbP9tYHX6HtboxTRYJ/7tA=
=0Sbv
-----END PGP SIGNATURE-----



Back to the top