BLOB and File Name

When using BLOB I want to be able to get JUST the filename, not the full path and stick it into a field associated with that attachment. So if someone imports c:\program files\office\officexp\excel\myspreadsheet.xls, how could I extract just “myspreadsheet” ? I do not see a string function that would allow me to find the last occurrence of a character, which is what I think I would need to find the last slash and take everything after that, but before the file extension. If anyone has any ideas please let me know

str1:=‘c:\program files\office\officexp\excel\myspreadsheet.xls’; while strpos(str1,’’)>0 do begin pos:= strpos(str1,’’); if pos<>0 then str1:= COPYSTR(str1, (pos+1) ); end; message(str1); and remove the last 4 chars. also