RSS订阅 | 匿名投稿
您的位置:网站首页 > 函数 > 正文

delphi GetMIMEType 查询文件MIME类型函数

作者:admin 来源: 日期:2018/2/7 10:40:21 人气: 标签:

uses Registry;

function GetMIMEType(FileName: String): String;

var
reg: TRegistry;
ext: String;
list: TStringList;
begin
Result := '';
ext := LowerCase(ExtractFileExt(Filename));
reg := TRegistry.Create;
try
reg.RootKey := HKEY_CLASSES_ROOT;
if reg.OpenKeyReadOnly('\' + ext) then begin
Result := reg.ReadString('Content Type');
reg.CloseKey;
end;
if Result = '' then begin
if reg.OpenKeyReadOnly('\MIME\Database\Content Type') then
begin
list := TStringList.Create;
try
reg.GetKeyNames(list);
for i := 0 to list.Count - 1 do begin
if Reg.OpenKeyReadOnly('\MIME\Database\Content
Type\' + list[i]) then begin
if AnsiSameText(ext,
reg.ReadString('Extension')) then begin
Result := list[i];
Break;
end;
end;
end;
finally
list.Free;
end;
reg.CloseKey;
end;
end;
finally
reg.Free;
end;
if Result = '' then Result := 'application/octet-stream';
end;
读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址:
下一篇:没有资料