Skip to main content

sanitize_path

Function sanitize_path 

Source
pub fn sanitize_path(path: &Path) -> PathBuf
Expand description

Sanitizes a file path by cleaning the filename component.

This function applies filename sanitization to the filename part of a path while preserving the directory structure. Invalid Windows characters are replaced with underscores.

§Arguments

  • path - The path to sanitize

§Returns

Returns a new path with a sanitized filename.

§Examples

let bad_path = Path::new("data/my:file?.txt");
let clean_path = sanitize_path(bad_path);
assert_eq!(clean_path, Path::new("data/my_file_.txt"));