Skip to content

Commit

Permalink
fixed auto_rename bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zaxtyson committed Aug 12, 2020
1 parent 35820d2 commit 1e5a003
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lanzou/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ def auto_rename(file_path) -> str:
if not os.path.exists(file_path):
return file_path
fpath, fname = os.path.split(file_path)
fname_no_ext, extension = os.path.splitext(fname)
flist = [f for f in os.listdir(fpath) if re.fullmatch(rf"{fname_no_ext}\(?\d*\)?{extension}", f)]
return fpath + os.sep + fname_no_ext + '(' + str(len(flist)) + ')' + extension
fname_no_ext, ext = os.path.splitext(fname)
flist = [f for f in os.listdir(fpath) if re.fullmatch(rf"{fname_no_ext}\(?\d*\)?{ext}", f)]
count = 1
while f"{fname_no_ext}({count}){ext}" in flist:
count += 1
return fpath + os.sep + fname_no_ext + '(' + str(count) + ')' + ext

0 comments on commit 1e5a003

Please sign in to comment.