pub fn clean<P: AsRef<Path>>(path: P) -> PathBuf
Expand description

Clean the given path to according to a set of rules:

  1. Reduce multiple slashes to a single slash.
  2. Eliminate . path name elements (the current directory).
  3. Eliminate .. path name elements (the parent directory) and the non-. non-.., element that precedes them.
  4. Eliminate .. elements that begin a rooted path, that is, replace /.. by / at the beginning of a path.
  5. Leave intact .. elements that begin a non-rooted path.

If the result of this process is an empty string, return the string ".", representing the current directory.

Note that symlinks and absolute paths are not resolved.

Example

assert_eq!(clean("foo/../../bar"), PathBuf::from("../bar"));