Increment file counter suffix as much as needed to get a unique file name
This commit is contained in:
parent
af1525a2c3
commit
91370068e4
@ -286,14 +286,16 @@ def move_file_to_target_dir(
|
||||
target_ext = season_ep_str["ext"]
|
||||
target_file_name_plus_ext = f"{target_file_name}{target_ext}"
|
||||
|
||||
if target_file_name_plus_ext in target_file_list:
|
||||
log.debug(f"Intended file name already exists in target dir, incrementing counter ...")
|
||||
while target_file_name_plus_ext in target_file_list:
|
||||
log.debug(f"Intended file name already exists in target dir, incrementing counter suffix ...")
|
||||
episode_minus_counter = target_file_name[:-2]
|
||||
counter = target_file_name[-2:]
|
||||
counter_length = len(counter)
|
||||
counter_stripped = int(counter.lstrip("0"))
|
||||
counter_stripped += 1
|
||||
target_file_name = f"{episode_minus_counter}{str(counter_stripped).zfill(counter_length)}"
|
||||
target_file_name_plus_ext = f"{target_file_name}{target_ext}"
|
||||
|
||||
target_abs_path = os.path.join(target_dir, f"{target_file_name}{target_ext}")
|
||||
|
||||
try:
|
||||
|
Loading…
x
Reference in New Issue
Block a user