It happens that your application encounters a directory path that is relative to current folder or uses double dot for navigation, e.g. C:\A\B\..\C. This obviously is equivalent to the canonical path C:\A\C. How can one resolve the path to its canonical form?
3 Answers
This one uses the java io interface:
jFile=java.io.File(iPath);
oPath=jFile.getCanonicalPath;
It wouldn't need to change matlab's directory. It has other useful methods that may be found here.
Comments
The simplest way I know to convert a path to its canonical form is using cd command:
oPath = cd(cd(iPath));
Note that this would fail if the path does not exist on your file system.
Comments
Another way of doing it, without potentially throwing an exception, is using the what command:
pathInfo = what(iPath);
if ~isempty(pathInfo)
iPath = pathInfo.path;
end