Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve a relative directory path to canonical path in MATLAB/Octave

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?

like image 814
Mohsen Nosratinia Avatar asked Dec 21 '22 01:12

Mohsen Nosratinia


2 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.

like image 149
Werner Avatar answered Dec 26 '22 15:12

Werner


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.

like image 29
Mohsen Nosratinia Avatar answered Dec 26 '22 15:12

Mohsen Nosratinia