If a file has a {edition-(whatever)} section then copy it, otherwise add such a section if there are relevant {tags}

Any questions? Need some help?
Post Reply
Franky
Posts: 9
Joined: 31 Mar 2021, 16:38

If a file has a {edition-(whatever)} section then copy it, otherwise add such a section if there are relevant {tags}

Post by Franky »

I'm trying to get this logic working:
1. If a file has a {edition-(whatever)} section, copy it.
2. Else, add such a section if there are relevant {tags}.
3. Do nothing.

So far, I've tried

Code: Select all

{fn.match(/ \{edition-.*\}/) ? fn.match(/ \{edition-.*\}/) : " {edition-${tags[0]}}"}
This works for the first part, but doesn't add the tags section if edition section doesn't exist.

I've tried separating them out like this:

Code: Select all

{fn.match(/ \{edition-.*\}/) ? fn.match(/ \{edition-.*\}/)}
" {edition-${tags[0]}}"}
This does work the way I want if the file doesn't have the edition section, but if it does and it's a tag thats also in {tags} the section gets duplicated.

To explain further, this is so I can add custom editions that's not in {tags} and not have FileBot delete them.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Custom format - If/Then not working?

Post by rednoah »

You can't use fn.match() in conditions, because it is never false. It'll either return a match, or break the {...} expression:
viewtopic.php?t=1895

Franky wrote: 19 Dec 2022, 06:03 1. If a file has a {edition-(whatever)} section, copy it.
2. Else, add such a section if there are relevant {tags}.
3. Do nothing.
e.g.

Code: Select all

{ any{ fn.match(/ \{edition-.*\}/) }{ " {edition-${tags[0]}}" } }



:idea: Alternatively, you could just use the new {edition} binding. You'll have to upgrade to the latest beta revision though. Please read [DOCS] The movie {tags} and movie {edition} bindings for details:

Code: Select all

{ "{edition-$edition}" }
:idea: Please read the FAQ and How to Request Help.
Post Reply