I want help with some code to search all folders in a directory....
Printable View
I want help with some code to search all folders in a directory....
Search folders for what? Specific file, files or text in file(s)?
I want to search for tif-files on the cd in all folders...
Searches for *.mp3 in C: but this can be changed easily...
hope this helpsCode:'objects
'1 cmd button
'1 list box
'*********************
Private Sub Command1_Click()
List1.Clear
Me.MousePointer = vbHourglass
GetAllDirsFrom "c:"
Me.MousePointer = vbNormal
End Sub
Private Function GetAllDirsFrom(ByVal pstrDir As String)
Dim fso As FileSystemObject
Dim fldrMain As Folder
Dim fldrsSub As Folders
Dim fldr As Folder
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldrMain = fso.GetFolder(pstrDir & "\")
If Right(fldrMain.Path, 1) = "\" Then
AddAllFilesFrom Left(fldrMain.Path, Len(fldrMain.Path) - 1)
Else
AddAllFilesFrom fldrMain.Path
End If
' Recurse subdirectories
Set fldrsSub = fldrMain.SubFolders
For Each fldr In fldrsSub
GetAllDirsFrom fldr.Path
Next
DoEvents
End Function
Private Function AddAllFilesFrom(ByVal pstrDir As String)
strFile = pstrDir & "\" & Dir(pstrDir & "\*.mp3")
Do Until strFile = pstrDir & "\"
List1.AddItem strFile
strFile = pstrDir & "\" & Dir
Loop
End Function
~~~~~~~~~~
~~Chenko~~
~~~~~~~~~~