delphi GetMIMEType 查询文件MIME类型函数


本文整理自网络,侵删。

 

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;

相关阅读 >>

python4Delphi 示例应用程序在 Delphi 应用程序中运行简单的 python 脚本

Delphi 屏幕截屏

Delphi timagelist 中使用 透明 png 图标

md5unit.pas

Delphi formactivate与formshow事件有什么区别

Delphi简单加密解密

Delphi form生成时的事件次序

Delphi分别连接ms sqlserver、oracle和access数据库的连接字符串

Delphi 在ms access数据库中图像的存储和显示

Delphi读写文本文件 assignfile reset append

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...