Conditional Structures (if-then-else)

All about user-defined episode / movie format expressions
Locked
User avatar
rednoah
The Source
Posts: 19340
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Conditional Structures (if-then-else)

Post by rednoah »

Conditional Structures



You can use if-then-else blocks or the ternary operator for conditional code.



Example 1: Move 3D movies and normal movies into different folders:

Code: Select all

{fn =~ /3D/ ? '3D Movies' : 'Movies'}


Example 2: Add [10bit] to 10-bit videos but not to 8-bit videos:

Code: Select all

{if (bitdepth == 10) ' [10bit]'}

Code: Select all

{bitdepth == 10 ? ' [10bit]' : null}


Example 3: Sort movies into folders by collection if the movie belongs to a collection or genre folders if not:

Code: Select all

{any{collection}{genre}{'No Genre'}}
:idea: The any(Closure...) function will call each of the given Closures until it finds one that yields a non-empty result.



Example 4: Sort movies from different years into different destination folders:

Code: Select all

{
	if (y < 1960) {
		return "X:/Old Movie"
	} else if (y < 2020) {
		return "Y:/Classic Movie"
	} else {
		return "Z:/New Movie"
	}
}
:idea: Use the @file syntax for reading command-line arguments from external text files.





:!: Bindings and functions may throw exceptions so the result may be neither true nor false:

Code: Select all

{'Avatar'.match(/3D/) ? 'X' : 'Y'} ⇨ Exception: Pattern not found
:idea: Please read the FAQ and How to Request Help.
Locked