mirror of
https://github.com/SinTan1729/movie-rename.git
synced 2024-12-26 20:28:36 -06:00
Skip renaming if destination exists
This commit is contained in:
parent
29fd0c3646
commit
1309ed34b4
2 changed files with 12 additions and 3 deletions
|
@ -2,7 +2,7 @@ use inquire::{
|
||||||
ui::{Color, IndexPrefix, RenderConfig, Styled},
|
ui::{Color, IndexPrefix, RenderConfig, Styled},
|
||||||
Select,
|
Select,
|
||||||
};
|
};
|
||||||
use std::{collections::HashMap, fs, process::exit};
|
use std::{collections::HashMap, fs, path::Path, process::exit};
|
||||||
use tmdb::{model::*, themoviedb::*};
|
use tmdb::{model::*, themoviedb::*};
|
||||||
use torrent_name_parser::Metadata;
|
use torrent_name_parser::Metadata;
|
||||||
|
|
||||||
|
@ -117,7 +117,11 @@ pub fn process_file(
|
||||||
println!("[file] '{}' -> '{}'", file_base, new_name_with_ext);
|
println!("[file] '{}' -> '{}'", file_base, new_name_with_ext);
|
||||||
// Only do the rename of --dry-run isn't passed
|
// Only do the rename of --dry-run isn't passed
|
||||||
if dry_run == false {
|
if dry_run == false {
|
||||||
fs::rename(filename, new_name.as_str()).expect("Unable to rename file!");
|
if Path::new(new_name.as_str()).is_file() == false {
|
||||||
|
fs::rename(filename, new_name.as_str()).expect("Unable to rename file!");
|
||||||
|
} else {
|
||||||
|
eprintln!("Destination file already exists, skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(new_name_base, is_subtitle)
|
(new_name_base, is_subtitle)
|
||||||
|
|
|
@ -82,7 +82,12 @@ fn main() {
|
||||||
} else {
|
} else {
|
||||||
println!("[directory] '{}' -> '{}'", entry_clean, movie_name);
|
println!("[directory] '{}' -> '{}'", entry_clean, movie_name);
|
||||||
if settings["dry_run"] == false {
|
if settings["dry_run"] == false {
|
||||||
fs::rename(entry, movie_name).expect("Unable to rename directory!");
|
if Path::new(movie_name.as_str()).is_dir() == false {
|
||||||
|
fs::rename(entry, movie_name)
|
||||||
|
.expect("Unable to rename directory!");
|
||||||
|
} else {
|
||||||
|
eprintln!("Destination directory already exists, skipping...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue