Function dunce::simplified

source ·
pub fn simplified(path: &Path) -> &Path
Expand description

Takes any path, and when possible, converts Windows UNC paths to regular paths. If the path can’t be converted, it’s returned unmodified.

On non-Windows this is no-op.

\\?\C:\Windows will be converted to C:\Windows, but \\?\C:\COM will be left as-is (due to a reserved filename).

Use this to pass arbitrary paths to programs that may not be UNC-aware.

It’s generally safe to pass UNC paths to legacy programs, because these paths contain a reserved prefix, so will gracefully fail if used with legacy APIs that don’t support UNC.

This function does not perform any I/O.

Currently paths with unpaired surrogates aren’t converted even if they could be, due to limitations of Rust’s OsStr API.

To check if a path remained as UNC, use path.as_os_str().as_encoded_bytes().starts_with(b"\\\\").