Hi, i was wondering, how do you get a list of folders from a dir (e.g. C:\) then display them in a list box??
any ideas?
Regards,
Martin
Gaming Help And Info:
any ideas?
Regards,
Martin
Gaming Help And Info:
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Private Sub Form_Load()
Dim oFS As FileSystemObject
Dim oFolders As Folders
Dim oFolder As Folder
Dim itmX As ListItem
Dim sValue As String
Set oFolders = oFS.GetFolder("C:\WINDOWS")
For Each oFolder In oFolders
sValue = oFolder.Name
Set itmX = lvListView.ListItems.Add
itmX.Text = sValue
itmX.Tag = Trim(sValue)
Next
End Sub
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 = ""
[COLOR=blue][b]recurse_list Replace(Dir1 & "\", "\\", "\"), Text2[/b][/color]
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 [COLOR=blue][b]recurse_list(Path As String, Optional ext As String, Optional tabs As String)[/b][/color]
On Error Resume Next
Dim Folders() As String
Dim tmpExt() As String
Dim t1 As String, t2 As String
Folders = [COLOR=red][b]getFolders(Path)[/b][/color]
For i = 0 To UBound(Folders)
Text1 = Text1 & tabs & ">" & Folders(i) & vbCrLf
[COLOR=blue][b]recurse_list Path & Folders(i) & "\", ext, tabs & vbTab[/b]][/color]
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 [COLOR=red][b]getFolders(Path As String) As String()[/b][/color]
On Error Resume Next
Dim Folder As String
Dim Temp As String
Folder = Dir(Path & "*", vbDirectory)
While Folder <> ""
If Folder <> "." And Folder <> ".." Then
If GetAttr(Path & Folder) And vbDirectory Then
Temp = Temp & IIf(Temp <> "", "|", "") & Folder
End If
End If
Folder = Dir()
Wend
[COLOR=red][b]getFolders[/b][/color] = Split(Temp, "|")
End Function