rust binary include dir and get contents
Pub Date: 2023-09-15
cargo add include_dir
main.rs
fn main() { use include_dir::{include_dir, Dir}; const IMAGE_DIR: Dir<'_> = include_dir!("./imgs/"); std::fs::create_dir_all("new").unwrap(); IMAGE_DIR.extract("new").unwrap(); for file in IMAGE_DIR.files(){ let contents = file.contents(); std::fs::write("./new_imgs/[r]".replace("[r]", &file.path().display().to_string()), contents).unwrap(); } }
fn main() { use include_dir::{include_dir, Dir}; const PROJECT_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR"); let lib_rs = PROJECT_DIR.get_file("src/main.rs").unwrap(); let contents = lib_rs.contents_utf8().unwrap(); println!("{}", contents); }