File_Utilities module

reduce_path

procedureSource

A copy of path with the . words removed and each .. cancelled against the word before it.

reduce_path :: (path: Path) -> Path

A .. with nothing to cancel is kept in a relative path (../a), and dropped in a rooted one, where it would go above the root. Symbolic links are not looked at, so a/link/.. becomes a even if link points elsewhere. The result has a new words array (free it with array_free) whose words are the input's slices; the input is not changed.

Parameters

path: Path

Returns

Example↗
raw := parse_path("a/./b/../c", reduce = false);
tidy := reduce_path(raw);
assert(tidy.words.count == 2 && tidy.words[0] == "a" && tidy.words[1] == "c");
array_free(raw.words);
array_free(tidy.words);

See also