Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Command1.Caption = "List Folders"
Command1.Default = True
Command2.Caption = "Save Text"
cd1.Filter = "Text|*.txt|All|*.*"
cd1.DefaultExt = "txt"
cd1.CancelError = True
End Sub
Private Sub Command1_Click()
Text1 = ""
recurse_list Replace(Dir1 & "\", "\\", "\"), Text2
End Sub
Private Sub Command2_Click()
Err.Clear
On Error Resume Next
cd1.ShowSave
If Err.Number = 0 Then
If Dir(cd1.FileName) <> "" Then
If MsgBox("File Exists" & vbCrLf & "Overwrite", vbYesNo, "Overwrite") = vbYes Then
Open cd1.FileName For Output As #1
Print #1, Text1
Close
End If
Else
Open cd1.FileName For Output As #1
Print #1, Text1
Close
End If
End If
End Sub
Function recurse_list(Path As String, Optional ext As String, Optional tabs As String)
On Error Resume Next
Dim Folders() As String
Dim tmpExt() As String
Dim t1 As String, t2 As String
Folders = getFolders(Path)
For i = 0 To UBound(Folders)
Text1 = Text1 & tabs & ">" & Folders(i) & vbCrLf
recurse_list Path & Folders(i) & "\", ext, tabs & vbTab
Next
File = Dir(Path & "*")
While File <> ""
If ext <> "" Then
tmpExt = Split(Replace(ext, ",", "|"), "|")
For i = 0 To UBound(tmpExt)
t1 = UCase(Right(File, Len(tmpExt(i))))
t2 = UCase(tmpExt(i))
If t1 = t2 Then Text1 = Text1 & tabs & File & vbCrLf
Next
Else
Text1 = Text1 & tabs & File & vbCrLf
End If
File = Dir()
Wend
End Function
Function getFolders(Path As String) As String()
On Error Resume Next
Dim S As String
Dim Temp As String, Temp2() As String
S = Dir$(Path & "*", vbDirectory)
While Len(S)
If S <> "." And S <> ".." Then
If GetAttr(Path & S) And vbDirectory Then
Temp = Temp & IIf(Temp <> "", "|", "") & S
End If
End If
S = Dir$
Wend
getFolders = Split(Temp, "|")
End Function