Solved

Windows file find dialog box

Posted on 1998-10-15
12
137 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
 

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now