I want to be able to search for every file with an extection of .exe on my computer.
Printable View
I want to be able to search for every file with an extection of .exe on my computer.
Code:'Search a dir and subdirectories for a specific file pattern
Private Sub GetFiles(sPath As String)
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim sFilename As String
Dim fld
If fso.FolderExists(sPath) Then
sPath = sPath & IIf(Right$(sPath, 1) <> "\", "\", "")
sFilename = Dir(sPath & "*.exe")
Do While Len(sFilename)
List1.AddItem sPath & sFilename
sFilename = Dir
Loop
For Each fld In fso.GetFolder(sPath).SubFolders
GetFiles fld.Path
Next
End If
End Sub
Private Sub Command1_Click()
Call GetFiles("C:\")
End Sub
This example from John Percival may help you as well:
http://www.vb-world.net/demos/findfiles/