Solved

Windows file find dialog box

Posted on 1998-10-15
12
143 Views
Last Modified: 2010-04-30
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
Comment
Question by:sye
  • 6
  • 2
  • 2
  • +1
12 Comments
 
LVL 4

Expert Comment

by:mcix
ID: 1440042
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
 
LVL 3

Expert Comment

by:HATCHET
ID: 1440043
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
 

Author Comment

by:sye
ID: 1440044
Edited text of question
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:sye
ID: 1440045
Adjusted points to 200
0
 

Author Comment

by:sye
ID: 1440046
Edited text of question
0
 

Author Comment

by:sye
ID: 1440047
Edited text of question
0
 

Author Comment

by:sye
ID: 1440048
Edited text of question
0
 
LVL 4

Expert Comment

by:mcix
ID: 1440049
Hatchet,

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




0
 
LVL 2

Expert Comment

by:mkmccreary
ID: 1440050
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
 
LVL 2

Expert Comment

by:mkmccreary
ID: 1440051
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
 
LVL 3

Accepted Solution

by:
HATCHET earned 300 total points
ID: 1440052
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
 

Author Comment

by:sye
ID: 1440053
Adjusted points to 300
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question