Skip to content

Commit

Permalink
Merge pull request #27 from chezhj:b738x
Browse files Browse the repository at this point in the history
fix: Fixed rename with exisiting
  • Loading branch information
chezhj authored Nov 7, 2023
2 parents 7297ad7 + b27603d commit f55384a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 3 additions & 1 deletion build/make.cmd
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pip freeze
@echo off
pyinstaller --noconfirm --onedir --windowed --icon "C:/Code/sbRenamer/sbRenamer.ico" --clean --add-data "C:/Code/sbRenamer/sbRenamer.ico;." "C:/Code/sbRenamer/sbRenamer.py" --distpath "C:/Code/sbRenamer/output" --workpath C:\Users\hvdwa\AppData\Local\Temp\build --specpath C:\Users\hvdwa\AppData\Local\Temp\spec

2 changes: 1 addition & 1 deletion config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ auto_start = False
auto_hide = False
save_xml = False
number_of_days = 0
fms_format = BOTH
fms_format = b738x

15 changes: 12 additions & 3 deletions sbRenamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,8 @@ def rename_shortend(self, event, target_filename):
dest_file = pathlib.Path(new_file_path.parent / target_filename)
# keep the new file to be created to check new event
self.file_names_to_ignore.append(dest_file.name)
if self.model.save_existing_target and dest_file.is_file():
logging.debug("Destination file exits")
self.rename_existing_file(dest_file)
if dest_file.is_file():
self.handle_existing_destination(dest_file)

try:
new_file_path.rename(dest_file)
Expand All @@ -387,6 +386,16 @@ def rename_shortend(self, event, target_filename):
"Unable to rename %s to %s, error: %s", filename, dest_file, err
)

def handle_existing_destination(self, dest_file):
"""Removes or renames exisiting file"""
logging.debug("Destination file exits")
if self.model.save_existing_target:
logging.debug("Renaming Existing Destination")
self.rename_existing_file(dest_file)
else:
logging.debug("Removing Existing Destination")
os.remove(dest_file)

def rename_existing_file(self, file_to_rename):
"""renames file to samename with datetime"""

Expand Down

0 comments on commit f55384a

Please sign in to comment.