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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With