Crates.io | baad-file-name |
lib.rs | baad-file-name |
version | 1.0.0 |
source | src |
created_at | 2023-01-07 14:35:56.533531 |
updated_at | 2023-01-07 14:35:56.533531 |
description | Simple crate to derive a new file name from a source file name. |
homepage | |
repository | https://gitlab.com/baad-rust/baad-file-name |
max_upload_size | |
id | 753074 |
size | 5,009 |
This is a simple crate that exposes a single function:
fn derive_file_name(file_name: &Path,
output_folder: Some(&Path),
new_extension: &Path) -> Option<PathBuf>;
It will take the file name file_name
, and replace its folder part and
extension part. If an output folder is not given (i.e. output_folder
is
None
), the current directory is used instead.
file_name |
output_folder |
new_extension |
Result |
---|---|---|---|
"/folder/foo.txt" |
Some("/new_folder") |
"bar" |
"/new_folder/foo.bar" |
"/folder/foo.txt" |
None |
"bar" |
"<current_dir>/foo.bar" |
This is useful for writing tools that take an input file and outputs to one or many files whose file names are derived from the input file. For example, imagine a tool that takes a mardown file (with ".md" extension) and produces a HTML and CSS file with the same file name stem but with extensions ".html" and ".css".