Code covered by the BSD License  

Highlights from
absolutepath

3.0

3.0 | 2 ratings Rate this file 23 Downloads (last 30 days) File Size: 3.4 KB File ID: #29768

absolutepath

by

 

17 Dec 2010 (Updated )

Computes absolute path from relative paths

| Watch this File

File Information
Description

Computes absolute path from relative paths. Works on windows and linux. Improves on absolutepath from Jochen Lenz (http://www.mathworks.com/matlabcentral/fileexchange/3857-absolutepath-m).

Acknowledgements

Absolutepath.M inspired this file.

This file inspired Coverage Report Generator.

MATLAB release MATLAB 7.11 (R2010b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
18 Jan 2011 Jan Simon

Dear Jonathan, Thanks for updating your submission. The program is much faster now!
I still cannot process the example from the help section:
absolutepath('A:\MyProject\', 'C:\local\');
I tried is as:
absolutepath('C:\WinXP', cd)
But get a java.io.IOException "bad syntax for file name".
I think it is necessary to mention in the help section, that the file or folder must exist. And the important 3rd input should be explained also.

12 Jan 2011 Jonathan Karr

Thanks for the comments Jan. I completely departed from the original code I tried to patch from Jochen Lenz, and greatly simplified and sped the function per your suggestions. In my brief tests I find the new version is 10X faster (although still 5X slower than the mex file).

12 Jan 2011 Jan Simon

I cannot get it to work:
"cd('D:\Temp'); absolutepath('..')"
replies 'D:\Temp' instead of 'D:\'. "absolutepath('..', 'D:\Temp')" does not help also. "absolutepath('..\Temp')" does not work also. The documentation suggests, that "absolutepath('C:\WINXP', cd)" replies 'C:\WINXP', but the function stops with an error: "The path D:\Temp\C:\WINXP\ or file D:\Temp\C:\WINXP does not exist". For the same reasons, I cannot obtain the absolute path for e.g. "C:\WINXP\..".
The only valid results can be obtained, if a (nested) subfolder of the specified basefolder oder current directory is wanted.
"absolutepath('.', 'D:\')" replies 'D:', which differs from the correct 'D:\'.
The documentation is almost very good (H1 line, author, list of changes, syntax and examples), but the 2nd example 'A:\MyProject' seems to be unsolvable by the function (of course with an adjusted path name).
The function is rather slow: It needs 2.5 sec to convert the names of 837 M-files. GetFullPath from the FEX needs 0.05 sec for the same task.
Although the function is buggy, slow and works with a very limited sort of input, I really like the clear, simple and complete documentation and rate it with 3 stars.

11 Jan 2011 Abel Brown

need to check that the path actually exists. You can not resolve the relative path for a file or directory that does not exist!

For example if im in /Users/myName and i call

absolutepath('./some/file/that/dne')

your function returns

/Users/myName/some/file/that/dne/

which is wrong. Should return either

No such file or directory or []

Updates
11 Jan 2011

Per Abel Brown's comments adding optional error checking for absolute path of directories that don't exist

12 Jan 2011

responding to Jan Simon's comments by greatly simplifying and speeding up by using java.io.File methods

Contact us