Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the absolute path of the currently edited file in Eclipse

I'd like to write a plugin that does something with the currently edited file in Eclipse. But I'm not sure how to properly get the file's full path.

This is what I do now:

IFile file = (IFile) window.getActivePage().getActiveEditor.getEditorInput().
    getAdapter(IFile.class);

Now I have an IFile object, and I can retrieve it's path:

file.getFullPath().toOSString();

However this still only gives me the path relative to the workspace. How can I get the absolute path from that?

like image 796
levik Avatar asked Nov 18 '08 18:11

levik


People also ask

How do I get absolute path in Eclipse?

getRawLocation() . That returns an IPath , which also has a makeAbsolute() method if you want to be doubly sure you've got an absolute path. The link from IResource. getRawLocation() has been changed now.

How do you find the absolute path?

To find the full absolute path of the current directory, use the pwd command. Once you've determined the path to the current directory, the absolute path to the file is the path plus the name of the file.

How do I find the directory of a file in Eclipse?

Press the "Ctrl," "Shift" and "R" keys on your keyboard simultaneously. A pop-up window will open and you can type in the name of the file you wish to find. Eclipse uses intelligent matching. Once it matches the file, just press "Enter." This is the fastest way to find files of any type, including Java and PHP files.

What is absolute path of a file in Java?

An absolute path always contains the root element and the complete directory list required to locate the file. For example, /home/sally/statusReport is an absolute path. All of the information needed to locate the file is contained in the path string.


1 Answers

Looks like you want IResource.getRawLocation(). That returns an IPath, which also has a makeAbsolute() method if you want to be doubly sure you've got an absolute path.

like image 66
Chris Marasti-Georg Avatar answered Oct 11 '22 13:10

Chris Marasti-Georg