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

directory, matlab, octave, path

Solution

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.

Problem

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?

Original source