• 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;

  • 相关阅读:
    如何使用PL/SQL工具批量导出表、存储过程、序列
    oracle如何导出和导入数据库/表
    linux安装nginx
    Linux下nginx反向代理服务器安装与配置实操
    StringTokenizer
    mapreduce join
    mapreduce计数器
    hadoop分布式系统架构详解
    进程与线程
    hadoop第一个例子
  • 原文地址:https://www.cnblogs.com/yzryc/p/6150052.html
Copyright © 2020-2023  润新知