Option Explicit
Private sLog As String Private Sub LogFilesOfType(ByVal sType As String, Optional ByVal sInitDir As String = "C:\") Dim sSubFolder() As String Dim iSubFolder As Long Dim sDir As String Dim bLogged As Boolean On Error Resume Next If Right$(sType, 1) <> "," Then sType = sType & "," If Right$(sInitDir, 1) <> "\" Then sInitDir = sInitDir & "\" sDir = Dir(sInitDir & "*", vbArchive + vbHidden + vbNormal + vbReadOnly + vbSystem + vbDirectory) While Len(sDir) If (GetAttr(sInitDir & sDir) And vbDirectory) = vbDirectory Then If Left(sDir, 1) <> "." Then ReDim Preserve sSubFolder(iSubFolder) sSubFolder(iSubFolder) = sDir iSubFolder = iSubFolder + 1 End If ElseIf InStr(sDir, ".") Then If InStr(sType, Mid$(sDir, InStr(sDir, ".")) & ",") Then If Not bLogged Then ' sLog = sLog & vbCrLf & sInitDir & vbCrLf bLogged = True End If List1.AddItem sInitDir & sDir 'sLog = sLog & " " & Left$(sDir & Space(50), 50) & Chr(9) & Format(FileDateTime(sInitDir & sDir), "HH:MM:SS AM/PM MM/DD/YYYY") & Chr(9) & FileLen(sInitDir & sDir) & vbCrLf Caption = "Logged: " & Val(Mid$(Caption, 9)) + 1 End If End If sDir = Dir Wend If iSubFolder Then For iSubFolder = 0 To UBound(sSubFolder) Call LogFilesOfType(sType, sInitDir & sSubFolder(iSubFolder)) Next End If End Sub Private Sub Command1_Click() sLog = "" Call LogFilesOfType(".txt,.scr") Open "C:\Log.txt" For Output As 1 Print #1, sLog Close 1 Shell "notepad.exe C:\log.txt", vbNormalFocus End Sub |