Results 1 to 7 of 7

Thread: Search for location of a file

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Exclamation Search for location of a file

    Hi all,
    Is there some way to find where a particular file is situated. It may in any Drive/Folder. No we are not to use any drive/file listbox etc.. simply a command button which displays the location onto a lable or msgbox.

  2. #2
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Search for location of a file



    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Search for location of a file

    This will also work without the overhead of the FSO
    Code:
    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()
        Dim tempStr As String, Ret As Long
        'create a buffer string
        tempStr = String(MAX_PATH, 0)
        'returns 1 when successfull, 0 when failed
        Ret = SearchTreeForFile("c:\", "myfile.exe", tempStr)
        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

  4. #4
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Search for location of a file

    Nice one Hack, but what if more files with the same name in different folders?


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Search for location of a file

    Quote Originally Posted by Radjesh Klauke
    Nice one Hack, but what if more files with the same name in different folders?
    Then you wouldn't use that API.

    However, the original question was
    Quote Originally Posted by VBFnewcomer
    Is there some way to find where a particular file is situated.
    A particular file indicates the OP is interested in finding just one file.

  6. #6
    Hyperactive Member
    Join Date
    Oct 2001
    Location
    Washington DC
    Posts
    314

    Re: Search for location of a file

    Quote Originally Posted by VBFnewcomer
    Hi all,
    Is there some way to find where a particular file is situated. It may in any Drive/Folder. No we are not to use any drive/file listbox etc.. simply a command button which displays the location onto a lable or msgbox.
    I don't get it. There is no such concept as "a particular file" that I know about. There is just "all files that have name xxxxxxx".

    So do you want a listbox with all the directories that files with a given name appear in? A bit like the Windows F3 search?

    Mac

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: Search for location of a file

    Thank you both Radjesh & Hack, as well as Randem & Static (in the link thread).
    A particular file indicates the OP is interested in finding just one file.
    Hack was right. However the links provided me with enough material which I could use in another context. By the way which of the approaches is faster and take less mem Hack's or Randem or Static.

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