Good idea! Now you know some details of string manipulations!

Try GetStringToken and CountStringTokens, FindString, ReplaceString in order dodge the char for char inspection, as this will be faster.
This would always return the correct format of a file str$ :
str$ = "HELLO.bmp"
format$ = GetStringToken(str$, ".", CountStringTokens(str$, ".")) // this will return the final token
even when the file has multiple point chars in its name like "Hello.Image.Texture.PNG"
And this will return the correct name without the format:
filename$ = left( str$, len(str$) - len(format$) - 1 )
So by "Hello.Image.Texture.PNG" it will return filename$ = "Hello.Image.Texture"