'复制出IE临时文件夹内的SWF文件,也可以是其他类型的文件,这里只是简单演示用FSO遍历文件夹
'引用Microsoft Scripting RunTime
Dim m_objFSO As New FileSystemObject '定义文件系统对象
Private Declare Function SHGetSpecialFolderLocation Lib "Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Integer, ppidl As Long) As Long
Private Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As Long
Const MAX_LEN = 200 '字符串最大长度
Const PAGETMP = &H20& '网页临时文件
Private Sub Command1_Click()
Dim sTmp As String * MAX_LEN '存放结果的固定长度的字符串
Dim nLength As Long '字符串的实际长度
Dim pidl As Long '某特殊目录在特殊目录列表中的位置
Dim TStr As String
'获得网页临时文件夹
SHGetSpecialFolderLocation 0, PAGETMP, pidl
SHGetPathFromIDList pidl, sTmp
TStr = Left(sTmp, InStr(sTmp, Chr(0)) - 1)
SearchSwf TStr
End Sub
Private Sub SearchSwf(strPath As String)
Dim objFolder As Scripting.Folder '文件夹对象
Dim objFile As Scripting.File '文件对象
Dim objSubdirs As Scripting.Folders '文件夹集合对象
Dim objLoopFolder As Scripting.Folder '文件夹对象
Set objFolder = m_objFSO.GetFolder(strPath)
For Each objFile In objFolder.Files
If UCase$(Right$(objFile.ShortPath, 4)) = ".SWF" Then
FileCopy objFile.Path, "c:/TestSwf/" & objFile.Name
End If
Next objFile
Set objSubdirs = objFolder.SubFolders
For Each objLoopFolder In objSubdirs
SearchSwf objLoopFolder.Path
Next objLoopFolder
Set objSubdirs = Nothing
Set objFolder = Nothing
End Sub