Function osutils::path::relpath

source ·
pub fn relpath(base: &Path, path: &Path) -> Option<PathBuf>
Expand description

Return path relative to base, or raise PathNotChild exception.

The path may be either an absolute path or a path relative to the current working directory.

os.path.commonprefix (python2.4) has a bad bug that it works just on string prefixes, assuming that ‘/u’ is a prefix of ‘/u2’. This avoids that problem.

NOTE: base should not have a trailing slash otherwise you’ll get PathNotChild exceptions regardless of path.