Hey, glad to know my script is still (mostly) working for you :)
I am a little confused by the statement:
> ...picks up another plant with the species name "tersonia" and places it into the wrong folder.
'tersonia' should not match 'Paterson', so the move shouldn't happen.
Regardless, there are bound to be other cases, and this is the big gotcha with simple path matching.
There are a couple of ways out of this.
The easiest, as you allude to, is a double-check. That's fine for simple cases, but can get unwieldy if you run into lots of exceptions.
For now, though, if you want to take that approach, you can use something like these solutions:
Assuming you have three files "Patersonia.jpg", "Mega Patersonia.jpg" and "Sonia.jpg" that need to be sorted differently
One-liner:
else if (name of each_file contains "Patersonia") and (name of each_file does not contain "Mega Patersonia") then
-- move the file to a specific folder path
move each_file to folder "Macintosh HD:Users:stevendew:Documents:aussiecreatures:TO_UPLOAD:ZZZ_PLANTS_SORTED:Iridaceae:Nivenioideae:Patersonia"
In this case, the first check ("Patersonia") matches, but the second check fails, allowing you to filter them separately.
You can also cascade them using nested if statement:
else if (name of each_file contains "sonia") then
-- this will match all three (matching is case-insensitive by default), so filter it:
if (name of each_file contains "Mega Patersonia") then...
-- move the file to the Mega folder
else if (name of each_file contains "Patersonia") then
. -- move the file to the regular folder
else
-- if we get here, it doesn't match either of the other options, so
-- move the file to the default 'sonia' folder
end if
else if (name of each_file contains "next keyword") then...
This can get unwieldy, though, if you have many similar names.
The third option is a modification to the order in which you perform the checks.
By structuring the if/else statements to filter the most specific first, these items wouldn't then be processed by the subsequent filters. e.g. given the same list above:
else if (name of each_file contains "Mega Patersonia") then
-- move the file to the Mega folder
else if (name of each_file contains "Patersonia") then
-- move the file to the regular folder
else if (name of each_file contains "sonia") then
-- move the file to the default 'sonia' folder
else if (name of each_file contains "something else") then...
In this case, when the 'Sonia' item comes through the script, it doesn't match either of the first two checks and is caught by the third.
Similarly, when 'patersonia.jpg' comes in, it skips the first check (it doesn't match 'Mega Patersonia'), but catches the second. The third check is skipped since it's already found a match, and the 'else' makes sure the 'Sonia' check only runs if the preceding checks fail.
So careful strucuturing of the if/else statements can catch many of these, but in all these examples you have to have an idea of what the possible corner cases are.
Does that help?