下面是我写的一个函数,把所有的缓存文件路径添加到一个字符串列表中,直接看代码,带了注释。另外还有删除缓存等等大家自己到msdn找找。
需要引用
- function GetCacheFilePath(): TStringList;
- var
- pEntryInfo: PInternetCacheEntryInfo;
- lCacheDir, lEntrySize, lLastError: Cardinal;
- bLoop: Boolean;
- begin
- Result := nil;
-
-
- lEntrySize := 0;
- lCacheDir := FindFirstUrlCacheEntry(nil, TInternetCacheEntryInfo(nil^),
- lEntrySize);
- if lEntrySize = 0 then
- Exit;
-
- GetMem(pEntryInfo, lEntrySize);
-
- lCacheDir := FindFirstUrlCacheEntry(nil, pEntryInfo^, lEntrySize);
- if lCacheDir = 0 then
- begin
- FreeMem(pEntryInfo, lEntrySize);
- Exit;
- end;
-
- Result := TStringList.Create;
-
-
- while True do
- begin
- try
- Result.Add(string(StrPas(pEntryInfo^.lpszLocalFileName)));
- except
- end;
-
- FreeMem(pEntryInfo, lEntrySize);
-
- lEntrySize := 0;
- FindNextUrlCacheEntry(lCacheDir, TInternetCacheEntryInfo(nil^), lEntrySize);
-
- if GetLastError() = ERROR_INSUFFICIENT_BUFFER then
- GetMem(pEntryInfo, lEntrySize)
- else
- Break;
-
- FindNextUrlCacheEntry(lCacheDir, pEntryInfo^, lEntrySize);
- end;
-
-
- FindCloseUrlCache(lCacheDir);
-
- end;
http://blog.csdn.net/cwpoint/article/details/6438668
uses WinINet;
Function TForm1.GetCacheVerifyCodeFile(VerifyCodeURL:String; Var CacheVerifyCodeFile:String):Boolean; 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 begin 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; End; Application.ProcessMessages; Until (dwLastError = ERROR_NO_MORE_ITEMS);
If FileExists(f) Then Begin CacheVerifyCodeFile := f; Result := true; End; End; FreeMem(lpEntryInfo); FindCloseUrlCache(Hwd); End;
可用于在缓存中的验证码图片,或者防盗链的图片的采集,嘿嘿。
此函数有两个参数,第一个是网络图片地址,第二个是本地缓存地址。第二个作为输出端口。
http://www.cnblogs.com/toosuo/archive/2010/09/02/1815583.html
|
请发表评论