From bfc452f83573d7dd9995aeda37007f3aaa605bf5 Mon Sep 17 00:00:00 2001 From: "Oleg V. Polivets" Date: Tue, 20 Mar 2018 01:42:25 +0300 Subject: [PATCH] srt: generate unique name for bakup file --- pysrt/commands.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pysrt/commands.py b/pysrt/commands.py index b2bfa24..9b7ede2 100755 --- a/pysrt/commands.py +++ b/pysrt/commands.py @@ -178,8 +178,11 @@ def split(self): def create_backup(self): backup_file = self.arguments.file + self.BACKUP_EXTENSION - if not os.path.exists(backup_file): - shutil.copy2(self.arguments.file, backup_file) + backup_idx = 1 + while os.path.exists(backup_file): + backup_file = self.arguments.file + ('.%i' % backup_idx) + self.BACKUP_EXTENSION + backup_idx += 1 + shutil.copy2(self.arguments.file, backup_file) self.output_file_path = self.arguments.file self.arguments.file = backup_file