From 471e60fa6cf4de727bf870dafcbcbea8db9fb480 Mon Sep 17 00:00:00 2001 From: sreedev Date: Tue, 10 Jan 2023 20:23:53 -0500 Subject: [PATCH] added delete options --- src/app/file_manager.rs | 9 ++++++++- src/output.rs | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/app/file_manager.rs b/src/app/file_manager.rs index 9fdd0bb..4f57d81 100644 --- a/src/app/file_manager.rs +++ b/src/app/file_manager.rs @@ -1,7 +1,14 @@ use crate::database::File; use anyhow::Result; +use colored::Colorize; pub fn delete_files(files: Vec) -> Result<()> { - println!("{:?} DELETED", files); + files.into_iter().for_each(|file| { + match std::fs::remove_file(file.path.clone()) { + Ok(_) => println!("{}: {}", "DELETED".green(), file.path), + Err(e) => println!("{}: {}", "FAILED".red(), file.path) + } + }); + Ok(()) } diff --git a/src/output.rs b/src/output.rs index b70070c..74a1282 100644 --- a/src/output.rs +++ b/src/output.rs @@ -97,12 +97,14 @@ fn process_group_action(duplicates: &Vec, dup_index: usize, dup_size: usiz .into_iter() .any(|index| index > (duplicates.len() - 1)) { - println!("Err: File Index Out of Bounds!"); + println!("{}", "Err: File Index Out of Bounds!".red()); return process_group_action(duplicates, dup_index, dup_size, table); } print!("{esc}[2J{esc}[1;1H", esc = 27 as char); + if parsed_file_indices.is_empty() { return } + let files_to_delete = parsed_file_indices .into_iter() .map(|index| duplicates[index].clone());