Conditional Structures (if-then-else)
Posted: 03 Oct 2016, 18:53
Conditional Structures
You can use if-then-else blocks or the ternary operator for conditional code.
e.g. Move 3D movies and normal movies into different folders:
e.g. Move Anime movies and normal movies into different folders:
e.g. Move Anime episodes and normal TV series episodes into different folders:
e.g. Move Documentary episodes and normal TV series episodes into different folders:
e.g. Move 4K movies and normal movies into different folders:
e.g. Add [10bit] to 10-bit videos but not to 8-bit videos:
e.g. Sort movies into folders by collection if the movie belongs to a collection or genre folders if not:
The any(Closure...) function will call each of the given Closures until it finds one that yields a non-empty result.
e.g. Sort movies from different years into different destination folders:
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 one value nor another:
You can use if-then-else blocks or the ternary operator for conditional code.
e.g. Move 3D movies and normal movies into different folders:
Code: Select all
{ fn =~ /3D/ ? '3D Movies' : 'Movies' }
e.g. Move Anime movies and normal movies into different folders:
Code: Select all
{ anime ? 'Anime Movies' : 'Movies' }
e.g. Move Anime episodes and normal TV series episodes into different folders:
Code: Select all
{ anime ? 'Anime' : 'TV Shows' }
e.g. Move Documentary episodes and normal TV series episodes into different folders:
Code: Select all
{ genre ==~ /Documentary|News/ ? 'Documentaries' : 'TV Shows' }
e.g. Move 4K movies and normal movies into different folders:
Code: Select all
{ height > 2000 ? '4K Movies' : 'Movies' }
e.g. 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 }
e.g. 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'} }

e.g. 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"
}
}


Code: Select all
{'Avatar'.match(/3D/) ? 'X' : 'Y'} ⇨ Exception: Pattern not found