organize
organize copied to clipboard
filecontent filter + rename action = multiple renames
I have the following rule running on a current version of organize (installed via pip):
# try to extract the first date from the file and rename it accordingly
- name: date_rename
locations: /scan/ocr
filters:
- name
- extension: pdf
- filecontent: '(?P<m>[0123]\d)\.(?P<d>[01]\d)\.(?P<y>[12][09]\d\d)'
actions:
- rename: "{filecontent.y}-{filecontent.m}-{filecontent.d}_{name}.pdf"
Unfortunately after "rename", the filter triggers on the renamed file again and starts the action over and over... it seems to run 5 times and then proceeds with the next rule:
scan/ocr
20220401_173738.pdf
- (rename) Rename to /scan/ocr/2022-23-03_20220401_173738.pdf
2022-23-03_20220401_173738.pdf
- (rename) Rename to /scan/ocr/2022-23-03_2022-23-03_20220401_173738.pdf
2022-23-03_2022-23-03_20220401_173738.pdf
- (rename) Rename to /scan/ocr/2022-23-03_2022-23-03_2022-23-03_20220401_173738.pdf
2022-23-03_2022-23-03_2022-23-03_20220401_173738.pdf
- (rename) Rename to /scan/ocr/2022-23-03_2022-23-03_2022-23-03_2022-23-03_20220401_173738.pdf
2022-23-03_2022-23-03_2022-23-03_2022-23-03_20220401_173738.pdf
- (rename) Rename to /scan/ocr/2022-23-03_2022-23-03_2022-23-03_2022-23-03_2022-23-03_20220401_173738.pdf
Is there a way to stop the rule from targeting the renamed file again?
This is a bug and shouldn't happen.
I'm experiencing the same issue with the following:
rules:
- name: "Renaming DVD folders"
locations:
- path: "/mnt/backups/DVDs"
max_depth: null
targets: dirs
subfolders: true
filters:
- name:
contains: "DVD"
actions:
- echo: "{path}"
- rename:
name: "{name.replace('[DVD] ','')}-{name.replace(' ', '_')}-{name.replace(' [1080p]','')}"
on_conflict: "overwrite"
@drgrandios Your issue seems like a bug where files are handled multiple times where they shouldn't. It's on my todo.
@telometto I replicated your issue and found this is more like a documentation issue 😅 What you're trying to do is this:
actions:
- echo: "{path}"
- rename:
name: "{name | replace('[DVD] ','') | replace(' [1080p]','') | replace(' ', '_')}"
on_conflict: "overwrite"
{name.replace(sth, other) takes the name and replaces sth with other but works from the full name every time. By using pipes as in the example above you can chain multiple renames.
EDIT: You can also chain like this:
name: "{name.replace('[DVD] ','').replace(' [1080p]','').replace(' ', '_')}"`
Worked a charm! Appreciate it 😀
@drgrandios Thanks for reporting and sorry for the late reply. I kind of forgot about the first problem in this issue! This should be fixed in organize v3 because now all generated files are excluded for the rest of the rule.