| Crates.io | ntfsanitise |
| lib.rs | ntfsanitise |
| version | 0.3.0 |
| created_at | 2025-10-07 15:40:53.99603+00 |
| updated_at | 2026-01-20 23:16:44.380976+00 |
| description | Sanitise filenames for use on NTFS filesystems |
| homepage | |
| repository | https://gitlab.com/Lynnesbian/ntfsanitise |
| max_upload_size | |
| id | 1871826 |
| size | 50,090 |
A tiny crate for sanitising filenames for use on NTFS filesystems.
The set of banned characters are exported as the constant
BANNED.
// path-related features require the standard library
#[cfg(feature = "std")]
fn main() {
use ntfsanitise::{sanitise, is_dirty, is_clean, PathExt, PathBufExt};
use std::path::PathBuf;
// sanitise strings
let input = "unsuitable:filename?.txt";
assert!(is_dirty(input));
let sanitised = sanitise(input, "_");
assert_eq!(sanitised, "unsuitable_filename_.txt");
assert!(is_clean(sanitised));
// sanitise paths
let mut path = PathBuf::from("/home/user/<file>.txt");
assert!(path.is_dirty());
path.sanitise_filename("_");
assert!(path.is_clean());
assert!(path.file_name().is_some_and(|file_name| file_name.to_str() == Some("_file_.txt")));
}
#[cfg(not(feature = "std"))]
fn main() {
use ntfsanitise::{BANNED, is_clean, is_dirty};
// no_std support
assert!(is_dirty("unsuitable:filename.txt"));
assert!(is_clean("suitable_filename.txt"));
assert!(BANNED.contains(&'<'));
}