Skip to content

Commit

Permalink
fixed regex backslash bug #2
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmajewski committed Sep 7, 2023
1 parent 504327e commit 568941c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions rightclick_backup.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,15 @@ if len(sys.argv) >= 2:
os.makedirs(backup_dir)

if config_subfolders is True:
sub_dir = os.path.join(backup_dir, file_name)
full_file_name = f"{file_name}{file_extension}"
sub_dir = os.path.join(backup_dir, full_file_name)
if not os.path.isdir(sub_dir):
os.makedirs(sub_dir)
backup_dir = sub_dir

# REGEX MATCHING
pattern = re.compile(rf"{file_name}_(\d{{3}}){file_extension}")
# pattern = re.compile(rf"{file_name}_(\d{{3}}){file_extension}")
pattern = re.compile(file_name + r"_(\d{3})" + re.escape(file_extension))

backup_files = [f for f in os.listdir(backup_dir) if re.match(pattern, f)]
next_suffix = str(len(backup_files)).zfill(3)
Expand Down

0 comments on commit 568941c

Please sign in to comment.