Get the extension:
PARSE VALUE REVERSE( fullfilename ) WITH ext'.'base
ext = REVERSE( ext )
Determine file type with magic numbers:
file_size = STREAM( fullfilename, 'C', 'QUERY SIZE' )
IF file_size < 4 THEN RETURN 99 /* Error, not a complete file?! */
magic.1 = '55 122 188 175 39 28'
magic.1.format = '7z'
magic.2 = '80 75 3 4'
magic.2.format = 'zip'
magic.0 = 2
magic.0.max = 0
/* Build Magic Numbers */
DO i = 1 TO magic.0
magic.i.code = ''
DO j = 1 TO WORDS( magic.i )
magic.i.code = magic.i.code||D2C(SUBWORD( magic.i, j, 1 ))
END
magic.0.max = MAX( magic.0.max, WORDS( magic.i ) )
END
/* Read the first characters from the file */
input = CHARIN( fullfilename, 1, magic.0.max )
CALL STREAM fullfilename, 'C', 'CLOSE'
/* Compare the magic characters/numbers with the list we have */
DO i = 1 TO magic.0
DO j = 1 TO WORDS( magic.i )
IF LEFT( input, LENGTH( magic.i.code ) ) = magic.i.code THEN
RETURN magic.i.format
END
END
/* No match found */
RETURN ''