FileSystem Object - Return Internet Address

M

Matt

All,

For those who like the direct approach, here is my basic question --
Is there a way to return the Internet Address for a Temporary Internet
File? Read on for more details.

I have created a recursive procedure below that accesses the Temporary
Internet Files folder and searches for a specified file to delete.
(Thanks to posts by Chip, et. al.). My code is below (and I commented
out the objFile.Delete for those who would like to simply do a copy,
paste, change the strROOTDIR constant, run “TestDelete”, and then view
the Immediate Window).

I quickly found that this method of file deletion may not be the best
way to achieve my result, as not all files from a specific website
have the same diction in the file name. If there is a way to access
the "Internet Address" of the file, then I'll be able to search for
files from a specified website and thereby delete my desired files.
Though I am using late binding below, I did add the "Microsoft
Scripting Runtime" reference to determine the properties/methods
available to a file (hence all the Debug.Print lines in my code -
partly for my own discovery purposes). There isn't a property for
"Internet Address" though, or at least I'm not aware of what it may
be.

For example, browse out to your Temporary Internet Files via the
explorer window or the browser menu:
(1) typically: C:\Documents and Settings\*folder specific to your
machine*\Local Settings\Temporary Internet Files, or
(2) via Internet Explorer: Tools | Internet Options | <General Tab> |
<Browsing History Frame> Settings | View Files.

You'll find that the explorer window lists a column for "Internet
Address." I'm trying to read this property. Is there a way to return
the Internet Address for a Temporary Internet File? If so, what might
the code look like?

Thanks in advance.

Matthew Herbert

Option Explicit
'CHANGE THIS TO FIT YOUR MACHINE
Public Const strROOTDIR = "C:\Documents and Settings\Matt\Local
Settings\Temporary Internet Files\"
Sub TestDelete()
DeleteFilesInDirectory strROOTDIR, "search*"
End Sub

Sub DeleteFilesInDirectory(strDirectory As String, strFileName As
String)
'---------------------------------------------------------------------
'PURPOSE: Find the files, that are Like strFileName, located in
' strRoot and delete these files.
'
'strDirectory The "root" directory. This may or may not have a "\"
' at the end of the string, e.g. C:\Documents and
Settings
' or C:\Documents and Settings\ is acceptable.
'
'strFileName The file name, or name and wildcard, to delete. This
' needs to include the wildcard if so desired, e.g.
' there is no way to know whether to look for mtna* or
' *mtna*.
'---------------------------------------------------------------------

Dim objFSO As Object
Dim objFolder As Object

'Use late binding instead of having to check/add the FSO reference
Set objFSO = CreateObject("Scripting.FileSystemObject")

'return the folder you want to work with
Set objFolder = objFSO.GetFolder(strDirectory)

'this shouldn't occur, but if the text was input incorrectly it will
If objFolder Is Nothing Then
MsgBox "No folder was found! Be sure that you entered the
argument text correctly."
Exit Sub
End If

ClearFilesInFolders objFolder, strFileName

End Sub

Sub ClearFilesInFolders(objFolder As Object, strFileName As String)
'---------------------------------------------------------------------
'PURPOSE: Searches the files within the specified folder
' (objFolder) for a match to the file name
(strFileName).
' If a match is found, the file is deleted. This
' procedure is recursive; each file within a sub folder
' of the calling folder (objFolder) is searched.
'
'objFolder The folder to search
'
'strFileName The file name to search
'---------------------------------------------------------------------

Dim objFile As Object
Dim objSubFolder As Object

'loop through each file within the folder
For Each objFile In objFolder.Files

'if the file name is like strFileName, delete the file
If objFile.Name Like strFileName Then
Debug.Print "Name :"; objFile.Name
Debug.Print "ParentFolder:"; objFile.ParentFolder
Debug.Print "Attributes :"; objFile.Attributes
Debug.Print "Date Creat :"; objFile.DateCreated
Debug.Print "Date Acces :"; objFile.DateLastAccessed
Debug.Print "Date Modif :"; objFile.DateLastModified
Debug.Print "Drive :"; objFile.Drive
Debug.Print "Path :"; objFile.Path
Debug.Print "ShortName :"; objFile.ShortName
Debug.Print "ShortPath :"; objFile.ShortPath
Debug.Print "Size :"; objFile.Size
Debug.Print "Type :"; objFile.Type
'Debug.Print "IE Address :"; objFile.InternetAddress

'objFile.Delete
End If
Next objFile

'loop through each sub folder within the calling folder
For Each objSubFolder In objFolder.SubFolders
'Debug.Print "SubFolder: "; objSubFolder.Name

'use recursion
ClearFilesInFolders objSubFolder, strFileName
Next objSubFolder

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top