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).
Jonathan Karr (2019). absolutepath (https://www.mathworks.com/matlabcentral/fileexchange/29768-absolutepath), MATLAB Central File Exchange. Retrieved .
Dear Jonathan, Thanks for updating your submission. The program is much faster now!
I still cannot process the example from the help section:
I tried is as:
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.
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).
I cannot get it to work:
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.
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
your function returns
which is wrong. Should return either
No such file or directory or 
responding to Jan Simon's comments by greatly simplifying and speeding up by using java.io.File methods
Per Abel Brown's comments adding optional error checking for absolute path of directories that don't exist