Skip to content

Commit

Permalink
Improved batching.batch_delete_files
Browse files Browse the repository at this point in the history
  • Loading branch information
sgeulette committed Nov 27, 2024
1 parent 9b1b648 commit 7277c48
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Changelog
1.1.2 (unreleased)
------------------

- Nothing changed yet.

- Improved `batching.batch_delete_files`.
[sgeulette]

1.1.1 (2024-09-18)
------------------
Expand Down
15 changes: 8 additions & 7 deletions imio/pyutils/batching.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ def batch_delete_files(batch_keys, config, rename=True):
"""
if batch_keys is None:
return
files = [config[key] for key in ("pf", "cf") if config[key] and os.path.exists(config[key])]
files.extend([fn for fn in config["af"] if os.path.exists(fn)])
try:
for key in ("pf", "cf"):
if config[key] and os.path.exists(config[key]):
if rename:
os.rename(config[key], "{}.{}".format(config[key], datetime.now().strftime("%Y%m%d-%H%M%S")))
else:
os.remove(config[key])
for filename in files:
if rename:
os.rename(filename, "{}.{}".format(filename, datetime.now().strftime("%Y%m%d-%H%M%S")))
else:
os.remove(filename)
except Exception as error:
logger.exception("Error while renaming/deleting the file %s: %s", config["pf"], error)
logger.exception("Error while renaming/deleting the file %s: %s", filename, error)

0 comments on commit 7277c48

Please sign in to comment.