Hey guys I have a text box, and i was wondering if it was possible to search a computer from that textbox. Say if text1 had notepad.exe in it. I press a button and the computer searchs for that file and says file found if it did.
Thanks!!!!
Printable View
Hey guys I have a text box, and i was wondering if it was possible to search a computer from that textbox. Say if text1 had notepad.exe in it. I press a button and the computer searchs for that file and says file found if it did.
Thanks!!!!
Justin, there are so many threads and expamples in the code bank and in the classic vb (this) forum. You better put a search :)
This one is an identical thread to your one.
http://www.vbforums.com/showthread.p...ht=File+Search
Thanks, so I grabbed soem code out of that thread as the folllowing...
VB Code:
If txtFrmSlctn.Text = "Stainless Steel" Then optFrmSS.Value = True ElseIf txtFrmSlctn.Text = "Epoxy" ThenPublic Function RecurseFolderList(FolderName As String) As Boolean On Error Resume Next Dim fso, f, fc, fj, f1 Set fso = CreateObject("Scripting.FileSystemObject") If Err.Number > 0 Then RecurseFolderList = False Exit Function End If On Error GoTo 0 If fso.FolderExists(FolderName) Then Set f = fso.GetFolder(FolderName) Set fc = f.Subfolders Set fj = f.Files 'For each subfolder in the Folder For Each f1 In fc 'Do something with the Folder Name Debug.Print f1 'Then recurse this function with the sub-folder to get any' ' sub-folders RecurseFolderList (f1) Next 'For each folder check for any files For Each f1 In fj Debug.Print f1 'This is when the file will be listed Next Set f = Nothing Set fc = Nothing Set fj = Nothing Set f1 = Nothing Else RecurseFolderList = False End If Set fso = Nothing End Function
In this new case, can the code be modified to search for notepad.exe on the hard drive.
And and such could it be deleted if it was found.
And does this particular code need me to refernece the FileSystemObject?
If you use the FSO, it needs to be referenced.Quote:
Originally Posted by Justin M
I prefer using this APICode:Private Declare Function SearchTreeForFile Lib "imagehlp" _
(ByVal RootPath As String, ByVal InputPathName As String, _
ByVal OutputPathBuffer As String) As Long
Private Const MAX_PATH = 260
Private Sub Command1_Click()
Dim tempStr As String, Ret As Long
'create a buffer string
tempStr = String(MAX_PATH, 0)
'returns 1 when successfull, 0 when failed
Ret = SearchTreeForFile("c:\", Text1.Text, tempStr)
If Ret <> 0 Then
MsgBox "Located file at " + Left$(tempStr, InStr(1, tempStr, Chr$(0)) - 1)
Else
MsgBox "File not found!"
End If
End Sub
Hmm, I don't see File System Object in the referenes, is it known under another name?
Microsoft Scripting Runtime is what you are looking for.
Hmm I dont think I have a microsoft scripting runtime , but i have a microsoft script control 1.0 , would that be the same thing?
Do Project/References
Microsoft Scripting Run time is right below the Microsoft Script Control in the list.