How do I search a folder for a file?
Printable View
How do I search a folder for a file?
VB Code:
Private Sub Command1_Click() If Dir$("c:\autoexec.bat") <> vbNullString Then MsgBox "file exists" Else MsgBox "file doesn't exist" End If End Sub
Hack,
i just forgot one thing, how can i search for multiple files within a folder?
Quote:
Originally Posted by Harsh Gupta
VB Code:
If Dir("c:\*.txt") <> vbNullString Then MsgBox "Text files are in the root directory" Else MsgBox "No such file types exist" End If
my bad Hack, didn't post what exactly i wanted to ask.
if i am searching for text files within a folder (and its subfolder), i want to create a list of all text files, probably in a listbox showing their names. how can i do that?
Thanks Hack... Is it possible to add a reference that allows me to utilize an F3 thype search?
Quote:
Originally Posted by Harsh Gupta
VB Code:
Private Sub Command1_Click() Dim strFiles As String strFiles = Dir("d:\*.txt") Do While strFiles > "" List1.AddItem strFiles strFiles = Dir Loop End Sub
What do you mean by an "F3 type search"? :confused:Quote:
Originally Posted by stealth black
Thanks Hack.
he means that whenever user presses F3, it must trigger the Search button. i believe that F3 is a common Shortcut for searching, in Windows.Quote:
Originally Posted by Hack
Gotcha. Set the Form's KeyPreview property to True, and play around with this.Quote:
Originally Posted by Harsh Gupta
VB Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = vbKeyF3 Then 'run search code End If End Sub
Ok... Do you know what the code is for the search companion?
Search companion? :confused:Quote:
Originally Posted by stealth black
Ok, in XP, when you are in any folder brower, you press F3 and you get the search feature in the left pane. (You know, the dog, the magician, etc...) I'm building a resource locator for the customer service reps here, to bring all the crap they use in a day together. I am wanting it to be an XP style search for various PDFs and image file I have created for them....
I think the panels are COM components, but might be mistaken.
Hmm, like the Microsoft Common references?
Not really... Do you know what they are called? Because I have clean forgotten. Is it "Explorer Panes" or "Explorer Bars" ?
Well I don't know how you'd even start to go about implementing the shell ones in your own application (I looked a bit and found nothing), but if you feel like creating your own with a similar feel, vbAccelerator has an XP-style Explorer Bar control here.
Hey wait a minute! This is exactly what I need!
Too cool! Thanks
No problem, glad it helped :)