Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Dim tvn As Node
Dim oFso As Object
Dim oFolder
Dim oSubFolder
Dim oSubSubFolder
Dim oSubSubSubFolder
Dim oFile
Dim Folder As String
Function Arvore()
ListView7.ListItems.Clear ' this is where the files inside the selected folder appear'
Tree1.Nodes.Clear
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFso.GetFolder("path name here")
Folder = oFolder
Set tvn = Tree1.Nodes.Add(, tvwParent, Folder, "Name u want to appear on the root", 10)
'subfolders code below in case of need
For Each oSubFolder In oFolder.subfolders
fPath = oFolder + "\" + oSubFolder.Name
Set tvn = Tree1.Nodes.Add(Folder, tvwChild, fPath, oSubFolder.Name, 5)
SubFolder = oSubFolder
For Each oSubSubFolder In oSubFolder.subfolders
dPath = SubFolder + "\" + oSubSubFolder.Name
If oSubSubFolder.Name = "Imagens" Then
Set tvn = Tree1.Nodes.Add(SubFolder, tvwChild, dPath, oSubSubFolder.Name, 2)
ElseIf oSubSubFolder.Name = "PDFS" Then
Set tvn = Tree1.Nodes.Add(SubFolder, tvwChild, dPath, oSubSubFolder.Name, 3)
ElseIf oSubSubFolder.Name = "_Espanha" Then
Set tvn = Tree1.Nodes.Add(SubFolder, tvwChild, dPath, oSubSubFolder.Name, 7)
ElseIf oSubSubFolder.Name = "_França" Then
Set tvn = Tree1.Nodes.Add(SubFolder, tvwChild, dPath, oSubSubFolder.Name, 8)
ElseIf oSubSubFolder.Name = "_Angola" Then
Set tvn = Tree1.Nodes.Add(SubFolder, tvwChild, dPath, oSubSubFolder.Name, 6)
ElseIf oSubSubFolder.Name = "_Portugal" Then
Set tvn = Tree1.Nodes.Add(SubFolder, tvwChild, dPath, oSubSubFolder.Name, 9)
ElseIf oSubSubFolder.Name = "_S. Tome e Principe" Then
Set tvn = Tree1.Nodes.Add(SubFolder, tvwChild, dPath, oSubSubFolder.Name, 1)
Else
Set tvn = Tree1.Nodes.Add(SubFolder, tvwChild, dPath, oSubSubFolder.Name, 5)
End If
SubSubFolder = oSubSubFolder
For Each oSubSubSubFolder In oSubSubFolder.subfolders
sPath = SubSubFolder + "\" + oSubSubSubFolder.Name
Set tvn = Tree1.Nodes.Add(SubSubFolder, tvwChild, sPath, oSubSubSubFolder.Name, 4)
Next
Next
Next
End Function
Private Sub Tree1_NodeClick(ByVal Node As Object)
Dim lvwItem As ListItem
ListView7.ListItems.Clear
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFso.GetFolder(Me.Tree1.SelectedItem.Key)
Folder = oFolder
For Each oFile In oFolder.Files
'the code below here is just to give icons to the files that will appear in the listview control'
If oFile.Type = "Microsoft Excel Worksheet" Then
Set lvwItem = ListView7.ListItems.Add(, , oFile.Name, 1, 1)
ElseIf oFile.Type = "Microsoft Office Access Application" Then
Set lvwItem = ListView7.ListItems.Add(, , oFile.Name, 3, 3)
ElseIf oFile.Type = "Adobe Acrobat Document" Then
Set lvwItem = ListView7.ListItems.Add(, , oFile.Name, 4, 4)
ElseIf oFile.Type = "Microsoft Word Document" Then
Set lvwItem = ListView7.ListItems.Add(, , oFile.Name, 5, 5)
ElseIf oFile.Type = "Imagem JPEG" Then
Set lvwItem = ListView7.ListItems.Add(, , oFile.Name, 2, 2)
ElseIf oFile.Type = "Imagem de mapa de bits" Then
Set lvwItem = ListView7.ListItems.Add(, , oFile.Name, 2, 2)
End If
Next
End Sub
Private Sub ListView7_Click()
' this is just in case of clicking on the listview without any items there...it will give u an error if theres nothing to click without the code below(at least in mine is like this xD)
Me.Fl.Value = ""
If ListView7.ListItems.Count = 0 Then
MsgBox "No files found on the folder"
Else
Me.Fl.Value = Me.Tree1.SelectedItem.Key + "\" + Me.ListView7.SelectedItem.Text
End If
End Sub
Private Sub ListView7_DblClick()
' the Fl is a hidden textbox that i use to save the full path of the file to execute it'
Me.Fl.Value = ""
Me.Fl.Value = Me.Tree1.SelectedItem.Key + "\" + Me.ListView7.SelectedItem.Text
If Me.ListView7.SelectedItem.Icon = 1 Then
ShellExecute Me.hwnd, "Open", Me.Fl, 0&, 0&, vbMinimized
End If
End Sub