rust-crates / ergo_fs

ergonomic filesystem operations in rust
https://docs.rs/ergo_fs
Other
7 stars 0 forks source link

Path parsing / joining should auto-simplify the path #10

Open epage opened 6 years ago

epage commented 6 years ago
use std::path::PathBuf;

fn main() {
    let path = PathBuf::from("empty//dot/./parent/../");
    println!("base {:?}", path);
    println!("join(empty) {:?}", path.join(PathBuf::from("")));
    println!("join(dot) {:?}", path.join(PathBuf::from(".")));
    println!("join(./) {:?}", path.join(PathBuf::from("./")));
}

playground

From what I gather, std::path seems to focus on being a low level API that can work on non-traditional systems. This means it cannot assume what is intended by extraneous/s,., or..`.

Yes, there is canonicalize but sometimes you need it done on relative paths when doing comparisons.

Python's pathlib automatically cleans up paths like this.