From 7e97138032a085dc7c46287b92417b0c630764de Mon Sep 17 00:00:00 2001 From: Jeffrey Portman Date: Tue, 29 Aug 2023 00:18:54 -0400 Subject: [PATCH 1/2] Add overwrite_smaller move conflict option.\nThis option overwrite the destination file path with the source file path if the source is larger than the destination. --- organize/actions/_conflict_resolution.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/organize/actions/_conflict_resolution.py b/organize/actions/_conflict_resolution.py index 8558a4b8..1e82a185 100644 --- a/organize/actions/_conflict_resolution.py +++ b/organize/actions/_conflict_resolution.py @@ -15,6 +15,7 @@ CONFLICT_OPTIONS = ( "skip", "overwrite", + "overwrite_smaller", "trash", "rename_new", "rename_existing", @@ -98,6 +99,21 @@ def resolve_overwrite_conflict( dst_fs.remove(dst_path) return dst_path + elif conflict_mode == "overwrite_smaller": + print(f"Overwrite Smaller {safe_description(dst_fs, dst_path)}.") + src_file_larger = src_fs.getsize(src_path) > dst_fs.getsize(dst_path) + if not simulate: + if dst_fs.isdir(dst_path): + dst_fs.removedir(dst_path) + elif dst_fs.isfile(dst_path): + if src_file_larger: + dst_fs.remove(dst_path) + if src_file_larger: + return dst_path + else: + print("Skipped.") + return None + elif conflict_mode == "rename_new": stem, ext = splitext(dst_path) name = next_free_name( From cbbe0a7c304ebded8ae1a65613c5ced00738c576 Mon Sep 17 00:00:00 2001 From: Jeffrey Portman Date: Tue, 29 Aug 2023 00:28:11 -0400 Subject: [PATCH 2/2] Add documentation for . --- docs/actions.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/actions.md b/docs/actions.md index b44526f0..a6f7a853 100644 --- a/docs/actions.md +++ b/docs/actions.md @@ -260,6 +260,22 @@ rules: on_conflict: "overwrite" ``` +Use a placeholder to move all .pdf files into a "PDF" folder and all .jpg files into a +"JPG" folder. Existing files will be overwritten only if they are larger than the existing file. + +```yaml +rules: + - locations: ~/Desktop + filters: + - extension: + - pdf + - jpg + actions: + - move: + dest: "~/Desktop/{extension.upper()}/" + on_conflict: "overwrite_smaller" +``` + Move pdfs into the folder `Invoices`. Keep the filename but do not overwrite existing files. To prevent overwriting files, an index is added to the filename, so `somefile.jpg` becomes `somefile 2.jpg`. ```yaml