pub fn normalize_file_path(file_path: &str) -> Result<PathBuf, PathError>Expand description
Normalizes and validates a file path for cross-platform compatibility
This function handles:
- Resolving relative paths (like
./file.txtor.\file.txton Windows) - Converting paths to absolute canonical form
- Validating that the path points to a regular file
- Cross-platform path separator handling
§Arguments
file_path- The file path to normalize (can be relative or absolute)
§Returns
Ok(PathBuf)- The normalized canonical pathErr(PathError)- If the path is invalid, doesn’t exist, or isn’t a file
§Examples
use hygg_shared::normalize_file_path;
// Works with relative paths
let path = normalize_file_path("./test.txt")?;
// Works with absolute paths
let path = normalize_file_path("/home/user/document.pdf")?;
// Works with Windows-style paths
let path = normalize_file_path(r".\document.docx")?;