How do you search within a folder for specific files? I've got browse functionality included to get to the folder I want.
Cheers
Printable View
How do you search within a folder for specific files? I've got browse functionality included to get to the folder I want.
Cheers
Add this module, add a drive list box and a command button....
Private Sub FindIt(sStartPath As String, sPattern As String)
On Error GoTo VenError:
Dim fso As FileSystemObject
Dim fld As Folder
Dim fldCurrent As Folder
Dim sFile As String
Screen.MousePointer = vbHourglass
Set fso = New FileSystemObject
If Right$(sStartPath, 1) <> "\" Then
sStartPath = sStartPath & "\"
End If
Set fldCurrent = fso.GetFolder(sStartPath)
sFile = Dir(sStartPath & sPattern, vbNormal)
Do While Len(sFile) > 0
List1.AddItem sStartPath & sFile
sFile = Dir
Loop
end sub
in the command button:
Call FindIt(Drive1.Drive & "\", "*.mdb")
Where u can specify the file type u need instead of "mdb".
Hope this helps,
Venkat.
Venkat
Thanks for the code but I can't get it to work. An error came up with the call FindIt to say that it isn't defined, so I made in public, now I've got an error with the FileSystemObject and Folder saying that the user types aren't defined. What should I do.
V
Venkatraman is using the File System Objects which requires the MS Scripting Runtime File(s).
Goto Project.. References and put a Check in MS Scripting Runtime and it should recognize them.
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
Thank You........Again!