List and optionally delete Internet Explorer cache files...
Posted: Tue Nov 04, 2003 1:04 am
Well, let's see if this works for everyone (MSDN says it works on all versions of Windows with IE4.0+)...
The default demo code just lists the files, so don't be afraid!
More info here for anyone who wants to explore further:
http://msdn.microsoft.com/library/defau ... ctions.asp
The default demo code just lists the files, so don't be afraid!
More info here for anyone who wants to explore further:
http://msdn.microsoft.com/library/defau ... ctions.asp
Code: Select all
; -----------------------------------------------------------------------------
; Internet Explorer cache file enumeration (with optional deletion)...
; -----------------------------------------------------------------------------
; james @ hi - toro . com
; -----------------------------------------------------------------------------
; Cache entry structure...
Structure INTERNET_CACHE_ENTRY_INFO
dwStructSize.l
lpszSourceUrlName.s
lpszLocalFileName.s
CacheEntryType.l
dwUseCount.l
dwHitRate.l
dwSizeLow.l
dwSizeHigh.l
LastModifiedTime.FILETIME
ExpireTime.FILETIME
LastAccessTime.FILETIME
LastSyncTime.FILETIME
*lpHeaderInfo.l
dwHeaderInfoSize.l
lpszFileExtension.s
StructureUnion
dwReserved.l
dwExemptDelta.l
EndStructureUnion
EndStructure
; Library number we'll use for wininet.dll...
#WININET = #9998
Procedure ListCacheEntries (delete)
; Open wininet.dll...
If OpenLibrary (#WININET, "wininet.dll")
; First call must fail in order to get size required for structure's buffer (fbuffsize)...
enum = CallFunction (#WININET, "FindFirstUrlCacheEntryA", #NULL, @fail, @fbuffsize)
If enum = #NULL
; Need larger buffer...
If GetLastError_ () = #ERROR_INSUFFICIENT_BUFFER
; Allocate a buffer of the required size, with cache entry structure...
*ic.INTERNET_CACHE_ENTRY_INFO = AllocateMemory (0, fbuffsize)
; Try again with new size and buffer...
enum = CallFunction (#WININET, "FindFirstUrlCacheEntryA", #NULL, *ic.INTERNET_CACHE_ENTRY_INFO, @fbuffsize)
If enum <> #NULL
; Got first cache entry!
Debug *ic\lpszSourceUrlName ; URL
Debug *ic\lpszLocalFileName ; Local cache file
; Delete cache entry if delete parameter = #TRUE...
If delete
If CallFunction (#WININET, "DeleteUrlCacheEntry", *ic\lpszSourceUrlName)
Debug "(Deleted)"
Else
Debug "(Failed to delete)"
EndIf
EndIf
Debug ""
; Release the buffer...
FreeMemory (0)
; Now iterate through the rest...
*ic = #NULL ; Being a good citizen since I intend to use this pointer again...
Repeat
; *ic is #NULL on the first call, and nbuffsize is 0 (it will be given correct value if there is an entry)...
result = CallFunction (#WININET, "FindNextUrlCacheEntryA", enum, *ic.INTERNET_CACHE_ENTRY_INFO, @nbuffsize)
If result = #FALSE
; Failed, so was it due to insufficient buffer, or end of cache entries?
error = GetLastError_ ()
Select error
Case #ERROR_NO_MORE_ITEMS
; End of cache entries -- 'done' variable is used to exit Repeat... Until loop...
done = #TRUE
Case #ERROR_INSUFFICIENT_BUFFER
; nbuffsize was 0, so allocate buffer (FindNextUrlCacheEntryA gave nbuffsize the correct value)...
*ic.INTERNET_CACHE_ENTRY_INFO = AllocateMemory (0, nbuffsize)
; (This will then hit 'Until' and go back to 'Repeat', calling the function with a buffer, plus correct nbuffsize.)
EndSelect
Else
; FindNextUrlCacheEntryA returned #TRUE in 'result' variable...
Debug *ic\lpszSourceUrlName
Debug *ic\lpszLocalFileName
; Delete cache entry if delete parameter = #TRUE...
If delete
If CallFunction (#WININET, "DeleteUrlCacheEntry", *ic\lpszSourceUrlName)
Debug "(Deleted)"
Else
Debug "(Failed to delete)"
EndIf
EndIf
Debug ""
; Free this buffer now...
FreeMemory (0)
; Reset nbuffsize to 0 so next FindNextUrlCacheEntryA will fail and allocate buffer as before...
nbuffsize = 0
EndIf
Until done
; Release cache enumeration handle...
CallFunction (#WININET, "FindCloseUrlCache", enum)
EndIf
EndIf
EndIf
; Close wininet.dll...
CloseLibrary (#WININET)
EndIf
EndProcedure
; D E M O . . .
; Pass '1' instead to delete all cache files (use at own risk, but works fine here!)...
ListCacheEntries (0)