CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2000
    Location
    south korea-seoul
    Posts
    13

    search a file in vb

    how can i search a file in windows system using vb program.? i just need a code for that.

    thank u and regards.
    bhaskar reddy.


  2. #2
    Join Date
    Jul 2000
    Location
    Hawaii
    Posts
    281

    Re: search a file in vb

    If Dir$("c:\windows\system\seekfile.ext") <> "" Then
    'file is found


  3. #3
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: search a file in vb

    Here is a sample program that uses the "SearchforFile" API to scan a directory tree for a specified file. IN the example it is looking for VB6.exe

    option Explicit

    '1).Start a new project.
    '2).Add a Animation Control to the form. (The animation control is part of "Microsoft Windows Common Controls-2 6.0 in the Project Components list.
    '3).Add a Command Button (Command1).
    '4).Paste the following code into the General Declarations section of the Form.
    '5).Edit the code, looking for the "AVIFile = " statement and make sure it has the correct path to the "Search.avi" file.
    '6).Change the statement which reads "Ret = SearchTreeForFile("C:\", "vb6.exe", tempStr)" to the executable of your choice.
    '7).Run the program



    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()
    'KPD-Team 2000
    'URL: http://www.allapi.net/
    'E-Mail: [email protected]
    ' Note: Search AVI stuff added by me jgd
    Dim tempStr as string, Ret as Long
    Dim AVIFile as string
    'create a buffer string
    me.Show
    AVIFile = "C:\Program Files\Microsoft Visual Studio\Common\Graphics\Videos\search.avi"
    anmAVI.Open AVIFile
    anmAVI.Play
    'returns 1 when successfull, 0 when failed
    tempStr = string(MAX_PATH, 0)
    Ret = SearchTreeForFile("C:\", "vb6.exe", tempStr)
    anmAVI.Stop
    anmAVI.Close
    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





    John G

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured