Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

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??
0
sye
Asked:
sye
  • 6
  • 2
  • 2
  • +1
1 Solution
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
syeAuthor Commented:
Adjusted points to 300
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 6
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now