Results 1 to 15 of 15

Thread: How to get a pathway from a filename?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    How to get a pathway from a filename?

    Hi there folks. If I was searching for pathway, I don't really need the filename, but the pathway would be very useful to me, would anyone have any recommendations on how to search for it? Like if I was looking for an mp3 file called. Howdy.mp3 for example, and I typed that into a textbox, what would be best and efficient to look for the path. Maybe I could have another textbox with the pathway showing up without a filename.

    Thank you so much for you ideas!

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: How to get a pathway from a filename?

    Another idea I just though of, is I don't actually need the full path, as I can use app.path for that. But the trick is the mp3 file in question could be in 1 of 68 sub folders in the app.path.

    Is there a function that takes a filename and just gives you in a msgbox what folder it is in? That would work in this case! : )

  3. #3
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How to get a pathway from a filename?

    Windows Search was re-done after Windows XP. It has a "high level" SQL-like API and a "low level" API for querying. Of course it only covers parts of the filesystem that you have allowed it to index.

    Aside from that all you can do is trawl through the directories yourself each time you want to search. That isn't too bad as long as you are just looking for files by name, but it falls apart if you need to search by content because you'd have to read and decode the format of various kinds of content within each file.


    You seem to be asking for something very simple though, something the Dir$() function already does for you. Just use that to walk the directory tree of interest until you find your match.

  4. #4
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    554

    Re: How to get a pathway from a filename?

    I know of no simple approach. You might want to check out the code at the following link

    http://www.developerfusion.com/code/...ile-searching/

    I'm not saying this is what you want to get into it is just one of several hits I found and I just picked it mainly at random. Maybe it's an over kill, I don't know and I didn't study it to see if it is even workable. I did a Google search on "Find File VB6"
    Last edited by Code Dummy; Jul 15th, 2017 at 01:08 PM.

  5. #5
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How to get a pathway from a filename?

    What about multiple hits?

    There might be 2, 4, 100 different files with the same name within the directory tree of interest.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: How to get a pathway from a filename?

    Speaking of finding a match, I'm wondering if this will help. The sub folders that are randomly used are in a listbox, so I know the pathway up until I get to the subfolder for the specific mp3 file. Is there something DIR$ can do to loop through a listbox of subfolders to find a match, and then once it finds a match, to use that sub folder listbox item?

  7. #7
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: How to get a pathway from a filename?

    So are you looking to find a file just by knowing the file name or are you looking to extract the path from the full filename as the title suggests?

    One way to extract the path portion of the full file pathname is to use InstrRev() and look for the last \ in the name, everything before that is your path.
    If you are looking and have only the filename then you have to scan for it using either DIR$() API or other methods.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: How to get a pathway from a filename?

    My apologies if I sound like I'm going back and forth Yes, I have the filename, but what I am looking for is the pathway that goes before the filename. If I were to enter a filename in a textbox, InstrRev() would be able to give me the full path way in a second textbox? Do you know any google searches I could find a code snippet?

  9. #9
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How to get a pathway from a filename?

    No, he was saying if you have the full path of the file you can "back up over" the name at the end to get the folder's path.

    There is no magic: if you want to search you have to search.

  10. #10
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    554

    Re: How to get a pathway from a filename?

    Did you look at the code from the link in post #4

  11. #11
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How to get a pathway from a filename?

    No need to direct somebody to another site when we have so many examples posted here.

  12. #12
    Fanatic Member
    Join Date
    Apr 2017
    Posts
    554

    Re: How to get a pathway from a filename?

    Oh, OK.
    Last edited by Code Dummy; Jul 15th, 2017 at 09:39 PM.

  13. #13
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How to get a pathway from a filename?

    Example using a hacked version of DirLister from the CodeBank:

    Name:  sshot1.png
Views: 188
Size:  3.0 KB

    Note that depending on the pattern (even a full file name with no wildcard symbols) there may well be multiple hits though:

    Name:  sshot2.jpg
Views: 179
Size:  31.0 KB

    DirLister accepts pattern strings of the form used by the VB6 Like operator, more powerful than the simpler wildcard patterns supported by FindFirstFile/FindNextFile or the Dir$() function alone.

    Code:
    Private Sub cmdSearch_Click()
        Dim ParentPath As String
        Dim Name As String
        Dim PastFirstRow As Boolean
    
        With flexResults
            .Rows = 2
            .TextMatrix(1, 0) = vbNullString
            DirLister.Start txtPath.Text, dlNormal Or dlReadOnly, txtPattern.Text, False, 0
            Do While DirLister.Dir(ParentPath, Name)
                If PastFirstRow Then
                    .Rows = .Rows + 1
                Else
                    PastFirstRow = True
                End If
                .TextMatrix(.Rows - 1, 0) = ParentPath
                .TextMatrix(.Rows - 1, 1) = Name
            Loop
            DirLister.Finish
        End With
    End Sub
    Attached Files Attached Files
    Last edited by dilettante; Jul 16th, 2017 at 11:05 AM.

  14. #14
    Addicted Member
    Join Date
    Aug 2017
    Location
    South Africa (in the middle)
    Posts
    160

    Re: How to get a pathway from a filename?

    I wonder how many programs will we get if each of us place all our data/programs (which we written ourselves) on one computer...
    Last edited by Inside; Aug 7th, 2017 at 11:04 PM.

  15. #15
    Addicted Member
    Join Date
    Aug 2017
    Location
    South Africa (in the middle)
    Posts
    160

    Re: How to get a pathway from a filename?

    Quote Originally Posted by dilettante View Post
    Example using a hacked version of DirLister from the CodeBank:
    Very good. Had a bit of a problem to add the flexgrid and got this from the original form to set (for others with a similar problem):
    Name:  Image 008.png
Views: 169
Size:  21.5 KB

    It works a lot faster than the original (I think, as I have it - but not mine. Found in Planet Source).

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