search filename for "." and then offset by the previous - or _

For some reason text offsets and the way the work just dont stick in my head. And so I’m asking another question relating to it.

Is there a way to get the offset of the last - or _ before a . in a file name?

I need to make folders for files based on there file names but some files look like asdf-01_001.tif and others might be asdf_01_001.tif and yet others asdf_01_000001.tif

I think the common point is that if the folder name was made from the text before the last dash or underscore I’m golden. Unless I get files asdf 01 0001.tif :lol:

Thanks in advance

set fileName to "asdf_01_000001.tif"

set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "_"

set folderName to text 1 thru text item -2 of fileName

set AppleScript's text item delimiters to astid

folderName --> "asdf_01"

It looks so easy when you write :lol::lol:

Thanks so much