In reply to Peter.

To extract the extension from a filename use the SCAN() function. But watch out for filenames without any periods or file names that start with period (hidden files on Unix).
if index(filename,'.') > 1 then extenstion=lowcase(scan(filename,-1,'.'));