Open
Conversation
- added a sanitize_string function to sanitize strings for filenames or directories - used this function to sanitize strings before constructing file paths - modify the regular expression to correctly match filenames that start with the sanitized filename - changed the file renaming process to use shutil.move instead of Path(filename_temp).rename(filename) to handle potential issues when the source and destination are in the same directory (files being renamed to "._1") needs to be tested more, but it fixes the problem.
|
I know you said it still needs testing but I hit an album where I can consistently reproduce and I get the error with this one even with your patch. |
if not check_id and check_name:
# Convert filename to a string before escaping
filename_str = str(PurePath(filename))
pattern = re.escape(filename_str) + '_'
c = len([file for file in Path(filedir).iterdir() if re.search(f'^{pattern}', str(file))]) + 1
fname = PurePath(filename).stem
ext = PurePath(filename).suffix
# Use the filename_str for pattern matching and then construct the new filename with the original Path object
filename = PurePath(filedir).joinpath(f'{fname}_{c}{ext}')Won't this be enough to fix it? It works for me hahaha |
|
This was my fix, got the line count down and haven't had any naming issues since. Didn't do any sanitization though. if not check_id and check_name:
c = len([file for file in Path(filedir).iterdir() if file.match(filename.stem + "*")])
filename = PurePath(filedir).joinpath(f'{filename.stem}_{c}{filename.suffix}')Got around having to use shutil when renaming temps this way. if filename_temp != filename:
if Path(filename).exists():
Path(filename).unlink()
Path(filename_temp).rename(filename)Both implemented on my fork and works well enough for me. I have not tested it extensively, though. I will probably come back to this. |
Contributor
|
There is already a function for sanitising strings for file names. Lines 245 to 266 in fa2156b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
needs to be tested more, but it fixes the problem from the title.