zoukankan      html  css  js  c++  java
  • delphi判断文件类型

    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;

  • 相关阅读:
    04_Windows平台Spark开发环境构建
    Hadoop Streaming 使用及参数设置
    Kafka 及 PyKafka 的使用
    Database Subquery
    Miscellaneous
    Emacs
    算法归纳
    逆元求组合数
    Elasticsearch 原理
    Linux的内存分页管理【转】
  • 原文地址:https://www.cnblogs.com/yzryc/p/6150052.html
Copyright © 2011-2022 走看看