解决方案 »
- TList问题
- 高手帮忙解答一下多线程互斥对象,谢谢
- 在没有安装Delphi6的机器上如何设置ODBC连接Delphi6自己的数据库(*.db)
- 请教如何在listview里显示树型结构??
- Error creating cursor handle
- 请问不用promptdatasource如何自己设置adoconnection数据链接属性对话框
- 网络游戏外挂制作之我所见(4)
- 如何检测“LPT1” 端口是否可以用!求高手!
- 求凭证录入控件???
- tag属性怎么用??
- 如何在richedit和memo中给有字符的行加上背景色?
- 请问ReadString读INI文件问题?怎么读取TMemo.Lines的类型
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
function GetIeTempFilePath():string;
public
{ Public declarations }
end;var
Form1: TForm1;implementation
uses Registry;
{$R *.dfm}
function TForm1.GetIeTempFilePath():string;
var reg:Tregistry;
KeyList: TStringList;
i: Integer;
begin
reg:=Tregistry.create;
KeyList := TStringList.Create;
reg.RootKey := HKEY_CURRENT_USER;
reg.openkey('Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', False);
reg.GetValueNames(KeyList);
for i := 0 to KeyList.Count - 1 do
begin
if KeyList[i] = 'Templates' then
begin
Result := reg.ReadString(KeyList[i]);
Exit;
end;
end;
reg.CloseKey;
reg.free;
KeyList.Free;
end;
function GetFileSize1(const FileName: string):integer;
var
f: TFileStream;
begin
f:=TFileStream.Create(FileName,fmOpenRead or fmShareDenyNone);
Result:=f.Size;
F.Free;end;procedure TForm1.Button1Click(Sender: TObject);
var filePath:string;
begin
filePath := GetIeTempFilePath;
if FileExists(filePath+'\a.jpg') then
begin
ShowMessage(IntToStr(GetFileSize1(filePath+'\a.jpg')));
end
else
ShowMessage('文件不存在!');
end;end.我的方式是从注册表中获取文件路径
这里面的IE临时文件路径是否获取正确了呢?我在我的本机测试是没问题的,从注册表获取到了值的话应该也不会出错
WinInet;FindFirstURLCacheEntry
FindNextUrlCacheEntry
DeleteUrlCacheEntry
var
lpEntryInfo: PInternetCacheEntryInfo;
dwEntrySize, dwLastError, Hwd: LongWORD;
i, j: Integer;
f: String;
begin
Result := False;
dwEntrySize := 0;
j := 0;
CacheVerifyCodeFile := '';
FindFirstUrlCacheEntry(nil , TInternetCacheEntryInfo(nil^) , dwEntrySize);
GetMem(lpEntryInfo , dwEntrySize);
Hwd := FindFirstUrlCacheEntry(nil , lpEntryInfo^ , dwEntrySize);
if Hwd <> 0 Then begin
Repeat
dwEntrySize := 0;
FindNextUrlCacheEntry(Hwd , TInternetCacheEntryInfo(nil^) , dwEntrySize);
dwLastError := GetLastError();
if dwLastError = ERROR_INSUFFICIENT_BUFFER then begin
GetMem(lpEntryInfo , dwEntrySize);
if FindNextUrlCacheEntry(Hwd , lpEntryInfo^ , dwEntrySize) then
if Pos(UpperCase(VerifyCodeURL) , UpperCase(lpEntryInfo.lpszSourceUrlName)) > 0 then begin
i := FileAge(lpEntryInfo.lpszLocalFileName);
if i > j then begin
j := i;
f := lpEntryInfo.lpszLocalFileName;
end else DeleteUrlCacheEntry(lpEntryInfo.lpszSourceUrlName);
end;
end;
Until (dwLastError = ERROR_NO_MORE_ITEMS);
if FileExists(f) then begin
CacheVerifyCodeFile := f;
Result := True;
end;
end;
FreeMem(lpEntryInfo);
FindCloseUrlCache(Hwd);
End;