feat: move files

This commit is contained in:
2026-08-19 21:15:56 +02:00
parent 63fb8890ee
commit bae8adea05
6 changed files with 247 additions and 12 deletions
+21 -9
View File
@@ -1,17 +1,22 @@
use clap::Parser;
use lofty::file::TaggedFileExt;
use lofty::probe::Probe;
use std::env;
use std::fs::rename;
use std::path::PathBuf;
#[derive(Parser)]
#[command(version, about, long_about = None)]
struct Args {
file: PathBuf,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Vec<String> = env::args().collect();
let args = Args::parse();
let file_path = args.file;
let target_dir = PathBuf::from("./test");
let target = target_dir.join(&file_path);
if args.len() < 2 {
return Err("Not a file. Usage: music-sort <file_path>".into());
}
let file_path = &args[1];
let tagged_file = Probe::open(file_path)
let tagged_file = Probe::open(&file_path)
.expect("ERROR: Bad path provided!")
.read()
.expect("ERROR: Failed to read file!");
@@ -24,5 +29,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}
let _ = move_files(target, file_path);
Ok(())
}
fn move_files(target: PathBuf, file_path: PathBuf) -> Result<(), Box<dyn std::error::Error>> {
rename(file_path, target)?;
Ok(())
}