|
-
Aug 26th, 2007, 03:40 AM
#1
Thread Starter
PowerPoster
Search from a text box
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!!!!
-
Aug 26th, 2007, 04:20 AM
#2
Re: Search from a text box
Justin, there are so many threads and expamples in the code bank and in the classic vb (this) forum. You better put a search
-
Aug 26th, 2007, 04:26 AM
#3
Re: Search from a text box
-
Aug 26th, 2007, 04:37 AM
#4
Thread Starter
PowerPoster
Re: Search from a text box
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?
-
Aug 27th, 2007, 08:31 AM
#5
Re: Search from a text box
 Originally Posted by Justin M
And does this particular code need me to refernece the FileSystemObject?
If you use the FSO, it needs to be referenced.
I prefer using this API
Code:
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
-
Aug 28th, 2007, 10:36 PM
#6
Thread Starter
PowerPoster
Re: Search from a text box
Hmm, I don't see File System Object in the referenes, is it known under another name?
Last edited by Justin M; Aug 28th, 2007 at 11:13 PM.
-
Aug 29th, 2007, 01:07 PM
#7
Re: Search from a text box
Microsoft Scripting Runtime is what you are looking for.
-
Aug 29th, 2007, 05:37 PM
#8
Thread Starter
PowerPoster
Re: Search from a text box
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?
-
Aug 30th, 2007, 01:13 PM
#9
Re: Search from a text box
Do Project/References
Microsoft Scripting Run time is right below the Microsoft Script Control in the list.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|