Skip to content

Commit

Permalink
Added support for empty file finder
Browse files Browse the repository at this point in the history
  • Loading branch information
qarmin committed Sep 26, 2020
1 parent 338352f commit 2cf5dcd
Show file tree
Hide file tree
Showing 6 changed files with 444 additions and 11 deletions.
55 changes: 51 additions & 4 deletions czkawka_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ fn main() {
bf.set_excluded_directory(ArgumentsPair::get_argument(&arguments, "-e", false));
}

if ArgumentsPair::has_command(&arguments, "-s") {
let number_of_files = match ArgumentsPair::get_argument(&arguments, "-s", false).parse::<usize>() {
if ArgumentsPair::has_command(&arguments, "-l") {
let number_of_files = match ArgumentsPair::get_argument(&arguments, "-l", false).parse::<usize>() {
Ok(t) => {
if t == 0 {
println!("ERROR: Minimum one biggest file must be showed..");
Expand Down Expand Up @@ -242,6 +242,45 @@ fn main() {

bf.get_text_messages().print_messages();
}
"--y" => {
let mut yf = empty_files::EmptyFiles::new();

if ArgumentsPair::has_command(&arguments, "-i") {
yf.set_included_directory(ArgumentsPair::get_argument(&arguments, "-i", false));
} else {
println!("FATAL ERROR: Parameter -i with set of included files is required.");
process::exit(1);
}
if ArgumentsPair::has_command(&arguments, "-e") {
yf.set_excluded_directory(ArgumentsPair::get_argument(&arguments, "-e", false));
}
if ArgumentsPair::has_command(&arguments, "-k") {
yf.set_excluded_items(ArgumentsPair::get_argument(&arguments, "-k", false));
}

if ArgumentsPair::has_command(&arguments, "-o") {
yf.set_recursive_search(false);
}

if ArgumentsPair::has_command(&arguments, "-delete") {
yf.set_delete_method(empty_files::DeleteMethod::Delete);
}

yf.find_empty_files();

#[allow(clippy::collapsible_if)]
if ArgumentsPair::has_command(&arguments, "-f") {
if !yf.save_results_to_file(&ArgumentsPair::get_argument(&arguments, "-f", false)) {
yf.get_text_messages().print_messages();
process::exit(1);
}
}

#[cfg(not(debug_assertions))] // This will show too much probably unnecessary data to debug, comment line only if needed
yf.print_results();

yf.get_text_messages().print_messages();
}
"--version" | "v" => {
println!("Czkawka CLI {}", CZKAWKA_VERSION);
process::exit(0);
Expand Down Expand Up @@ -293,15 +332,23 @@ Usage of Czkawka:
Usage example:
czkawka --e -i "/home/rafal/rr, /home/gateway" -e "/home/rafal/rr/2" -delete
--b <-i directory_to_search> [-e exclude_directories = ""] [-k excluded_items = ""] [-s number_of_files = 50] [-x allowed_extension = ""] [-o] [-f file_to_save = "results.txt"]
--b <-i directory_to_search> [-e exclude_directories = ""] [-k excluded_items = ""] [-l number_of_files = 50] [-x allowed_extension = ""] [-o] [-f file_to_save = "results.txt"]
-i directory_to_search - list of directories which should will be searched like /home/rafal
-e exclude_directories - list of directories which will be excluded from search.
-k excluded_items - list of excluded items which contains * wildcard(may be slow)
-o - this options prevents from recursive check of folders
-f file_to_save - saves results to file
-s number_of_files - number of showed the biggest files.
-l number_of_files - number of showed the biggest files.
-x allowed_extension - list of checked extension, e.g. "jpg,mp4" will allow to check "book.jpg" and "car.mp4" but not roman.png. There are also helpful macros which allow to easy use a typcal extension like IMAGE("jpg,kra,gif,png,bmp,tiff,webp,hdr,svg") or TEXT("txt,doc,docx,odt,rtf")
--y <-i directory_to_search> [-e exclude_directories = ""] [-k excluded_items = ""] [-o] [-f file_to_save = "results.txt"] [-delete] - search for duplicates files
-i directory_to_search - list of directories which should will be searched like /home/rafal
-e exclude_directories - list of directories which will be excluded from search.
-k excluded_items - list of excluded items which contains * wildcard(may be slow)
-o - this options prevents from recursive check of folders
-f file_to_save - saves results to file
-delete - delete found files
--version / --v - prints program name and version
"###
Expand Down
2 changes: 1 addition & 1 deletion czkawka_core/src/big_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,6 @@ impl PrintResults for BigFile {
println!("{} ({} bytes) - {}", size.file_size(options::BINARY).unwrap(), size, entry.path);
}
}
Common::print_time(start_time, SystemTime::now(), "print_duplicated_entries".to_string());
Common::print_time(start_time, SystemTime::now(), "print_entries".to_string());
}
}
12 changes: 9 additions & 3 deletions czkawka_core/src/duplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,13 @@ impl SaveResults for DuplicateFinder {
}
};

match file.write_all(format!("Results of searching in {:?}\n", self.directories.included_directories).as_bytes()) {
match file.write_all(
format!(
"Results of searching {:?} with excluded directories {:?} and excluded items {:?}\n",
self.directories.included_directories, self.directories.excluded_directories, self.excluded_items.items
)
.as_bytes(),
) {
Ok(_) => (),
Err(_) => {
self.text_messages.errors.push(format!("Failed to save results to file {}", file_name));
Expand Down Expand Up @@ -565,7 +571,7 @@ impl SaveResults for DuplicateFinder {
}
}
} else {
file.write_all(b"Not found any empty folders.").unwrap();
file.write_all(b"Not found any duplicates.").unwrap();
}
Common::print_time(start_time, SystemTime::now(), "save_results_to_file".to_string());
true
Expand Down Expand Up @@ -627,7 +633,7 @@ impl PrintResults for DuplicateFinder {
panic!("Checking Method shouldn't be ever set to None");
}
}
Common::print_time(start_time, SystemTime::now(), "print_duplicated_entries".to_string());
Common::print_time(start_time, SystemTime::now(), "print_entries".to_string());
}
}

Expand Down

0 comments on commit 2cf5dcd

Please sign in to comment.