本文整理自网络,侵删。
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; 相关阅读 >>
Delphi 消息实现窗口最小化,最大化,关闭(Delphi)
Delphi用多媒体库 bass.dll 播放 mp3 - 打开、播放、暂停、停止
Delphi的webbrowser改造,对网页中alter等对话框的改造方法
更多相关阅读请进入《Delphi》频道 >>