Initial commit with code to run in a directory

This commit is contained in:
2026-05-21 17:54:02 -07:00
parent 8bd3efe693
commit 40de738fef
4 changed files with 690 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;
use structopt::StructOpt;
#[derive(StructOpt)]
struct Opts {
#[structopt(parse(from_os_str), required = true)]
directory: PathBuf,
}
fn convert_epub_to_mobi(directory: &Path) {
if let Err(e) = fs::read_dir(directory) {
eprintln!("Error reading directory: {}", e);
return;
}
for entry in fs::read_dir(directory).unwrap() {
let entry = entry.unwrap();
let path = entry.path();
if path.is_dir() {
convert_epub_to_mobi(&path);
} else if let Some(ext) = path.extension() {
if ext.to_str() == Some("epub") {
let input_path = path.to_str().unwrap();
let output_path = path.with_extension("mobi");
println!("Converting {} to {}", input_path, output_path.display());
Command::new("ebook-convert")
.args(&[input_path, output_path.to_str().unwrap()])
.status()
.unwrap();
}
}
}
}
fn main() {
let opts = Opts::from_args();
convert_epub_to_mobi(&opts.directory);
}