I have some filenames that end in a number of unique letters. for example some might end in -CF and some might end in -OVW
the filenames themselves are numbers with the postfix. So 00012-CF for example.
I know how to get the filename as a string, i get it from either photoshop or using a script that i already have. but i dont know how and cant find a way to search the string and check wether the characters after the final - are either CF OVW or more.
I reckon its a method and an if statement in that method that would return a value but i dont know how to really. The script must also be able to disregard the .jpg, but i think that i can just trim that if the filename has that file extension.
This appears to work, although I don’t know why it doesn’t fail when the name contains no period.
set name_ to "00012-CF.jpg"
set trimmed_ to (characters 1 thru ((offset of "." in name_) - 1) of name_) as text
if trimmed_ ends with "CF" or trimmed_ ends with "OVW" then
display dialog "ends in CF or OVW"
end if
set fileName to “00012-CF.jpg”
if fileName ends with “CF” then
display dialog “The file name does match”
else
display dialog “The file name does not match”
end if
Because the extension needs to be disregarded when doing the check. Jon’s script takes this into account without the extra step. My example would work even if the extension is something other than jpg.
I have done one better, this one sees whether it is there in any part of the filename.
it is also alot smaller and should run faster, also reduce typing.
if fileName contains "RO" then
display dialog "FileName contains RO"
end if