function getFileType(inputFile:string):string;
const
JPEG_FLAG_BEGIN = $D8FF;
JPEG_FLAG_END = $D9FF;
JPEG_FRAME = $C0FF;
GIF_FLAG_BEGIN=$4947;
GIF_FLAG_END=$3B00;
PNG_FLAG_BEGIN=$5089;
PNG_FLAG_END=$8260;
BMP_FLAG_BEGIN=$4D42;
EXE_FLAG_BEGIN=$5A4D;
ZIP_7Z_FLAG_BEGIN=$7A37;
ZIP_FLAG_BEGIN=$4B50;
var
FileStream: TFileStream;
BeginFlag,EndFlag: WORD;
begin
result:='Unkown';
FileStream:=nil;
try
FileStream := TFileStream.Create(inputFile,fmOpenRead);
FileStream.Position:=0;
FileStream.Read(BeginFlag, SizeOf(BeginFlag));
FileStream.Position := FileStream.Size - 2;
FileStream.Read(EndFlag, SizeOf(EndFlag));
if (BeginFlag = JPEG_FLAG_BEGIN) and (EndFlag = JPEG_FLAG_END) then
result:='JPG';
if (BeginFlag = GIF_FLAG_BEGIN) and (EndFlag = GIF_FLAG_END) then
result:='GIF';
if (BeginFlag = PNG_FLAG_BEGIN) and (EndFlag = PNG_FLAG_END) then
result:='PNG';
if (BeginFlag = BMP_FLAG_BEGIN) then
result:='BMP';
if (BeginFlag = EXE_FLAG_BEGIN) then
result:='EXE';
if BeginFlag =ZIP_7Z_FLAG_BEGIN then
result:='7Z';
if BeginFlag =ZIP_FLAG_BEGIN then
result:='Zip';
finally
freeandnil(FileStream);
end;
end;