Trouble looping through "Temporary Internet Files"

MiserableMad

Active member
Joined
Feb 2, 2007
Messages
25
Programming Experience
Beginner
This is the code I have...
The trouble is when ever it loops, it only returns one value(desktop.ini)

VB.NET:
 Try

            Const beginPath As String = "C:\Documents and Settings\"
            Const endPath As String = "\Local Settings\Temporary Internet Files"
            Dim fullPath As String = beginPath & Environment.UserName.ToString & endPath
            'Count the number of files
            Dim counter As Integer
            lstTemp.Items.Clear()

            Dim list As New IO.DirectoryInfo(fullPath)
            Dim file As IO.FileInfo() = list.GetFiles
            Dim fi As FileInfo
          
            For Each fi In file
                lstTemp.Items.Add(fi.FullName.ToString)
                counter += 1
                txtCounter.Text = counter
                txtCounter.Update()
            Next

            'put in alhpa numeric order
            lstTemp.Sorted = True


        Catch ex As Exception
            MsgBox(ex.Message, , Me.Text)
        End Try

What am I doing wrong?
 
It's a system cache, so safest is to use the special dedicated methods to interact with it, "How to clear the cache when your application hosts a WebBrowser control in Visual Basic .NET" may be helpful for you, it looks fairly complicated to use, but initially it's just a copy-paste. That code enumerates all the files in cache and deletes each. You can also remove the delete call and just use the code to enumerate the files, the only extra code needed from that to get the filename is this:
VB.NET:
Dim LocalFileName As String = Marshal.PtrToStringAnsi(internetCacheEntry.lpszLocalFileName)
With the local filename at hand you can access the file directly with regular methods, as far as I can tell. (except delete it directly through file system)
 
Dim LocalFileName As String = Marshal.PtrToStringAnsi(internetCacheEntry.lpszLocalFileName)

How would I initiate an enumeration?
internetCacheEntry is not declared (so what would I put)
I suppose it is in the "module1" ln. 39
VB.NET:
 enumHandle = Class1.FindFirstUrlCacheGroup(0, CACHEGROUP_SEARCH_ALL, IntPtr.Zero, 0, groupId, IntPtr.Zero)
        'If there are no items in the Cache, you are finished.
        If (Not enumHandle.Equals(IntPtr.Zero) And ERROR_NO_MORE_ITEMS.Equals(Marshal.GetLastWin32Error)) Then
            Exit Sub
        End If

        'Loop through Cache Group, and then delete entries.
        While (True)
            'Delete a particular Cache Group.
...
 
Enumerating the items or iterating them is different terms for looping over the collection, the code in the article does that to get all internet temp file items. The internetCacheEntry variable is declared in that example code (Module section).
 
Back
Top