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!
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! : )
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.
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"
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.
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?
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.
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? :)
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.
Re: How to get a pathway from a filename?
Did you look at the code from the link in post #4
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.
Re: How to get a pathway from a filename?
3 Attachment(s)
Re: How to get a pathway from a filename?
Example using a hacked version of DirLister from the CodeBank:
Attachment 149599
Note that depending on the pattern (even a full file name with no wildcard symbols) there may well be multiple hits though:
Attachment 149601
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
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...
1 Attachment(s)
Re: How to get a pathway from a filename?
Quote:
Originally Posted by
dilettante
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):
Attachment 150391
It works a lot faster than the original (I think, as I have it - but not mine. Found in Planet Source).