Listing Temporary Internet Files

  • Thread starter Thread starter Alan Phang
  • Start date Start date
A

Alan Phang

Why is it not possible to list the contents of the "Temporary Internet
Files" folder using the DIR function in Excel VBA ?

DIR invariably returns a null string even though there are many files in
that folder.

Appreciate any help.

AP
 
Alan,

Not quite as simple as it sounds. I personally don't know what on earth they
were doing when they came up with this amazing cache scheme for IE6, which I
presume is what you are working with. Anyway, this gets files into a new
workbook. Note, it's extracted from a vb routine I wrote a while back so it
uses vb constants but they seem to work fine on excel xp.

Option Explicit

Sub GetIECacheFiles()

Dim vDirList As Variant
Dim vDirName As Variant
Dim lFileCount As Long
Dim strRoot As String
Dim strName As String
Dim strFilter As String
Dim strFind As String

Workbooks.Add

strFilter = InputBox("If you wish to filter for a particular file type
please enter the extension")

strRoot = "C:\Documents and Settings\UserName\Local Settings\Temporary
Internet Files\Content.IE5\"

Call GetDirs(strRoot, vDirList)
lFileCount = 1

For Each vDirName In vDirList

strFind = vDirName & "\"
strFind = strFind & IIf(strFilter <> "", "*." & strFilter, "*.*")
strName = Dir(strFind, vbDirectory + vbHidden + vbSystem)

Do While strName <> ""

If strName <> "." And strName <> ".." Then

If (GetAttr(vDirName & strName) And vbDirectory) <> vbDirectory
Then

Cells(lFileCount, 1).Value = vDirName
Cells(lFileCount, 2).Value = strName
lFileCount = lFileCount + 1

End If

End If

strName = Dir

Loop

Next vDirName

End Sub

Private Sub GetDirs(strRoot, vDirList)
Dim strName As String

strName = Dir(strRoot, vbDirectory + vbHidden + vbSystem)
Do While strName <> ""
If strName <> "." And strName <> ".." Then
If (GetAttr(strRoot & strName) And vbDirectory) = vbDirectory Then
If IsEmpty(vDirList) Then
ReDim vDirList(0)
Else
ReDim Preserve vDirList(0 To UBound(vDirList) + 1)
End If
On Error GoTo 0
vDirList(UBound(vDirList)) = strRoot & strName & "\"
End If
End If
strName = Dir
Loop
End Sub

HTH,

Robin Hammond
www.enhanceddatasystems.com
 
Robin,

Thanks very much - it worked very nicely.

I'm not familiar with VB (as opposed to Excel VBA) - would greatly
appreciate if you could show me how I could modify the code to *list* and
*delete* the files immediately within the "Temporary Internet Files" folder
itself.

Thanks for your help. Appreciate it.

Alan
 
Back
Top