Crates.io | sanitize-filename |
lib.rs | sanitize-filename |
version | 0.5.0 |
source | src |
created_at | 2018-10-24 16:42:01.130066 |
updated_at | 2023-07-31 02:53:57.742374 |
description | A simple filename sanitizer, based on Node's sanitize-filename |
homepage | |
repository | https://github.com/kardeiz/sanitize-filename |
max_upload_size | |
id | 92411 |
size | 12,870 |
A basic filename sanitizer, based on Node's sanitize-filename.
Use like:
extern crate sanitize_filename;
fn main() {
println!("{}", sanitize_filename::sanitize("some-user-defined/../../../string"));
// prints some-user-defined......string
}
You can also configure a few basic options:
let options = sanitize_filename::Options {
truncate: true, // true by default, truncates to 255 bytes
windows: true, // default value depends on the OS, removes reserved names like `con` from start of strings on Windows
replacement: "" // str to replace sanitized chars/strings
};
let sanitized = sanitize_filename::sanitize_with_options("some-user-defined/../../../string", options);
Also provides a basic command line binary. Use like:
cargo install sanitize-filename
sanitize-filename my_filename.txt
Pass a file name to clean to the program (also reads STDIN)
FLAGS:
-r, --replace <r> Replacement characters
--windows, --no-windows Whether to handle filenames for Windows
--truncate, --no-truncate Whether to truncate file names to 255 bytes