Windows file find dialog box

How can I activate Windows 95 and NT file find function
and prefill specified boxes to do a search.  Is there an
API call?

HATCHET
The extra 100 are for you!!

Plus
for even more  "100"

Can either of you tell me now that I have the files listed how can I get the list into an array or file so I can read it in VB??
syeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mcixCommented:
This is how to show the dialog:

http://support.microsoft.com/support/kb/articles/q183/9/03.asp

I'm not sure about the search criteria...
0
HATCHETCommented:
sye,

mcix got this one.  I went to the web page above and got the code that Microsoft gives for starting up the Find dialog box and added a little of my own code to make it so that it not only starts it up and sits there, but enters the word to search for automatically then starts looking for that entry.  Here it is:
_________________________________________

Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const SW_SHOWNORMAL = 1
Private Const SW_SHOWMINIMIZED = 2
Private Const SW_SHOWMAXIMIZED = 3
Private Const SW_SHOW = 5
Private Const SW_MINIMIZE = 6
Private Const SW_SHOWMINNOACTIVE = 7
Private Const SW_SHOWNA = 8
Private Const SW_RESTORE = 9
Private Const SW_SHOWDEFAULT = 10

Private Sub Command1_Click()
   
   Call ShellExecute(Me.hwnd, "find", Dir1.Path, vbNullString, vbNullString, SW_SHOWNORMAL)
   DoEvents
   Sleep 2000
   SendKeys "Hello"
   DoEvents
   SendKeys "{ENTER}"

End Sub

Private Sub Drive1_Change()
   
   Dir1.Path = Drive1.Drive

End Sub

Private Sub Form_Load()
   
   Command1.Caption = "Search Selected Path"

End Sub
_________________________________________


mcix deserves the points for this one, but if you'd like to give me a few points for making the effort and giving you the code and then a little more, feel free.  If not, no biggie.  =]

HATCHET
0
syeAuthor Commented:
Edited text of question
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

syeAuthor Commented:
Adjusted points to 200
0
syeAuthor Commented:
Edited text of question
0
syeAuthor Commented:
Edited text of question
0
syeAuthor Commented:
Edited text of question
0
mcixCommented:
Hatchet,

Thanks for sharing the credit, but you did solve the whole problem...




0
mkmccrearyCommented:
This may be better.  I wrote a VB function that does a find and places the values in an array.  Here it is:

Sub FindFile(ByVal vstrDirectory As String, ByVal vstrSearchParms As String, sFiles() As String, Optional ByVal ClearFileCounter As Boolean = True)

Dim mstrDirectory As String
Dim mstrDirectorys() As String
Dim miCounter As Integer
Dim miDirectoryCount As Integer
Static lFileCounter As Integer
Dim lAttributes As Long

On Error GoTo FindFileError

If ClearFileCounter Then
    lFileCounter = 0
End If

miDirectoryCount = 0

'frmStatus.lblDirectory.Caption = vstrDirectory
'DoEvents

mstrDirectory = Dir$(vstrDirectory & "\" & vstrSearchParms)

While mstrDirectory <> ""
    Select Case mstrDirectory
        Case "."
            ' Current Directory - Skip
        Case ".."
            ' Parent Directory - Skip
        Case Else
            ' Add File To Array
            mstrDirectory = vstrDirectory & "\" & mstrDirectory
            ReDim Preserve sFiles(lFileCounter)
            sFiles(lFileCounter) = mstrDirectory
            lFileCounter = lFileCounter + 1
    End Select
    mstrDirectory = Dir$
Wend


mstrDirectory = Dir$(vstrDirectory & "\*.*", vbDirectory)

While mstrDirectory <> ""
    Select Case mstrDirectory
        Case "."
            ' Current Directory - Skip
        Case ".."
            ' Parent Directory - Skip
        Case Else
            ' Make Sure it is a directory
            mstrDirectory = vstrDirectory & "\" & mstrDirectory
            If GetAttr(mstrDirectory) And vbDirectory Then
                miDirectoryCount = miDirectoryCount + 1
                ReDim Preserve mstrDirectorys(miDirectoryCount)
                mstrDirectorys(miDirectoryCount) = mstrDirectory
                'Call FindFile(mstrDirectory, vstrRoll)
            End If
GetAttrErrorResume:
    End Select
    mstrDirectory = Dir$
Wend


For miCounter = 1 To miDirectoryCount
'    Debug.Print mstrDirectorys(miCounter)
    Call FindFile(mstrDirectorys(miCounter), vstrSearchParms, sFiles(), False)
Next miCounter

FindFileExit:
    Exit Sub

FindFileError:

    Select Case Err
        Case 5
            ' Invalid procedure call or argument, happens on open files and GetAttr
            Resume GetAttrErrorResume
'        Case 52
'            'Bad File Name or Number, occurs when a file is thought of as a directory
'            'This happens when the GetAttr() fails
'            Resume Next
        Case Else
            MsgBox "Error : " & Err & "     " & Error$(Err), 48
            Resume FindFileExit
    End Select

    Resume

End Sub



Here is a sample implementation of the code.  I placed it under a command button:

Dim sFileList() As String

Call FindFile("c:", "readme.txt", sFileList())

MsgBox "Done."


Have Fun,
Martin
0
mkmccrearyCommented:
Have an Improved version, I forgot something in the last one.  This one allows you to specify which file types you want to look for.  If you pass it vbNormal, it only finds files.  If you pass it vbNormal Or vbDirectory it finds files and directories meeting the criteria.  Here it is:

Sub FindFile(ByVal vstrDirectory As String, ByVal vstrSearchParms As String, sFiles() As String, Optional ClearFileCounter As Boolean = True, Optional FileFlags As Long = vbNormal)

Dim mstrDirectory As String
Dim mstrDirectorys() As String
Dim miCounter As Integer
Dim miDirectoryCount As Integer
Static lFileCounter As Integer
Dim lAttributes As Long

On Error GoTo FindFileError

If ClearFileCounter Then
    lFileCounter = 0
End If

miDirectoryCount = 0

'frmStatus.lblDirectory.Caption = vstrDirectory
'DoEvents

mstrDirectory = Dir$(vstrDirectory & "\" & vstrSearchParms, FileFlags)

While mstrDirectory <> ""
    Select Case mstrDirectory
        Case "."
            ' Current Directory - Skip
        Case ".."
            ' Parent Directory - Skip
        Case Else
            ' Add File To Array
            mstrDirectory = vstrDirectory & "\" & mstrDirectory
            ReDim Preserve sFiles(lFileCounter)
            sFiles(lFileCounter) = mstrDirectory
            lFileCounter = lFileCounter + 1
    End Select
    mstrDirectory = Dir$
Wend


mstrDirectory = Dir$(vstrDirectory & "\*.*", vbDirectory)

While mstrDirectory <> ""
    Select Case mstrDirectory
        Case "."
            ' Current Directory - Skip
        Case ".."
            ' Parent Directory - Skip
        Case Else
            ' Make Sure it is a directory
            mstrDirectory = vstrDirectory & "\" & mstrDirectory
            If GetAttr(mstrDirectory) And vbDirectory Then
                miDirectoryCount = miDirectoryCount + 1
                ReDim Preserve mstrDirectorys(miDirectoryCount)
                mstrDirectorys(miDirectoryCount) = mstrDirectory
                'Call FindFile(mstrDirectory, vstrRoll)
            End If
GetAttrErrorResume:
    End Select
    mstrDirectory = Dir$
Wend


For miCounter = 1 To miDirectoryCount
'    Debug.Print mstrDirectorys(miCounter)
    Call FindFile(mstrDirectorys(miCounter), vstrSearchParms, sFiles(), False, FileFlags)
Next miCounter

FindFileExit:
    Exit Sub

FindFileError:

    Select Case Err
        Case 5
            ' Invalid procedure call or argument, happens on open files and GetAttr
            Resume GetAttrErrorResume
'        Case 52
'            'Bad File Name or Number, occurs when a file is thought of as a directory
'            'This happens when the GetAttr() fails
'            Resume Next
        Case Else
            MsgBox "Error : " & Err & "     " & Error$(Err), 48
            Resume FindFileExit
    End Select

    Resume

End Sub



And here is a use of the new function:

Dim sFileList() As String

Call FindFile("c:", "Temp", sFileList(), , vbNormal Or vbDirectory)

MsgBox "Done."

Have Fun,
Martin
0
HATCHETCommented:
sye,

You said I'd get 100 points for the work I did.  So I'm answering instead of Commenting.   =]   Thanks for the points.

mkmccreary really did a good job with his method of find file as all of the finding is done inside of your application without having to go to one of Window's applications and all that.  You CAN easily "Remotly Control" that Windows app once it's up and all, but doing things inside your application is a more stream-lined way of doing things.  It's up to you which you use.  It really depends on what you're doing it for, ya know.  =]

HATCHET
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
syeAuthor Commented:
Adjusted points to 300
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.