清空internet临时文件夹Temporary Internet Files

    在XP平台上,直接调用DeleteFile()函数是不能删除临时文件夹里面的文件的!需要调用FindFirstUrlCacheEntry()和FindNextUrlCacheEntry()查找Internet Cache的入口,获取缓存文件夹里文件的信息,然后调用DeleteUrlCacheEntry()删除指定文件名的缓存文件;

添加头文件:wininet.h

添加引入库: Wininet.lib 和 shlwapi.lib

代码如下:

BOOL DeleteTempFile()
{
    BOOL bRet = FALSE;
    HANDLE hEntry;
    LPINTERNET_CACHE_ENTRY_INFO lpCacheEntry = NULL; 
    DWORD dwEntrySize;
 
    dwEntrySize = 0;
    hEntry = FindFirstUrlCacheEntry(NULL, NULL, &dwEntrySize);
    lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO) new char[dwEntrySize];
    hEntry =  (NULL, lpCacheEntry, &dwEntrySize);  //从Internet cache中找到特定入口
 
    if (!hEntry)
      goto cleanup;
 
    do
     {
        if (!(lpCacheEntry->CacheEntryType & COOKIE_CACHE_ENTRY))
                DeleteUrlCacheEntry(lpCacheEntry->lpszSourceUrlName);   //删除Cache中指定的文件
  
       dwEntrySize = 0;
       FindNextUrlCacheEntry(hEntry, NULL, &dwEntrySize);
       delete [] lpCacheEntry;
       lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO) new char[dwEntrySize];
     }
     while (FindNextUrlCacheEntry(hEntry, lpCacheEntry, &dwEntrySize));  //查找Internet cache的下一个入口
 
     bRet = TRUE;
  cleanup:
      if (lpCacheEntry)
          delete [] lpCacheEntry;
     return bRet;

}

你可能感兴趣的:(清空internet临时文件夹Temporary Internet Files)