![]() |
Path from path???
How to find/get the FULL path from a path with pattern recognition???
If I provide these paths: C:\Folder1\Folder2\Folder3\ C:\Fo?der1\Folder2\Folder3\ C:\Folder1\Fol*der2\Folder3\ C:\Folder1\Folde?2\?older3\ C:\Fol?er1\Fo*der2\Fo*der3\ C:\Fol*der1\Folder2\Fold?er3\ ....I would like to retreive C:\Folder1\Folder2\Folder3\ ....in all cases? Apparrently DIR() only give the last folder, and only if the middle folder doesn't contain a pattern char! FileSystemObject won't return and full path if given a pattern path! API 'GetLongPathName' fails completely if using pattern chars! What am I missing?!? ...and if I'm putting in the short name extender (~) everything goes south How to get the FULL path, no matter what pattern chars I have included in the path??? Thanks, CE |
Path from path???
Not sure where you get the idea Dir only gives the last folder. Dir works in
two ways, you can check if a particular folder (or file) exists, or you can loop (typically Do-While) an entire folder to return all its folders and subfolders until Dir returns empty. In the loop you can check for your pattern match, if it matches (eg with the Like operator) recursively call the same routine passing the found folder as the parent folder for the next call, and so on. Also pass the folder level incrementing with +1 (be sure to do that ByVal) and say a string array for each of your folder generations to compare with in the given "level". Also I don't follow what you mean or your objective when you say you "provide these paths". In the second example would "C:\FoDder1\Folder2\Folder3\" be correct or incorrect, and if incorrect why. What are you actually trying to do. You might also use FSO which is perhaps more intuitive, though generally I prefer Dir. Regards, Peter T "Charlotte E." wrote in message ... How to find/get the FULL path from a path with pattern recognition??? If I provide these paths: C:\Folder1\Folder2\Folder3\ C:\Fo?der1\Folder2\Folder3\ C:\Folder1\Fol*der2\Folder3\ C:\Folder1\Folde?2\?older3\ C:\Fol?er1\Fo*der2\Fo*der3\ C:\Fol*der1\Folder2\Fold?er3\ ...I would like to retreive C:\Folder1\Folder2\Folder3\ ...in all cases? Apparrently DIR() only give the last folder, and only if the middle folder doesn't contain a pattern char! FileSystemObject won't return and full path if given a pattern path! API 'GetLongPathName' fails completely if using pattern chars! What am I missing?!? ..and if I'm putting in the short name extender (~) everything goes south How to get the FULL path, no matter what pattern chars I have included in the path??? Thanks, CE |
Path from path???
What are you actually trying to do.
I need to know what full path a given pattern actually finds... ...no matter which or how many or where pattern chars are included. CE "Peter T" wrote in message ... Not sure where you get the idea Dir only gives the last folder. Dir works in two ways, you can check if a particular folder (or file) exists, or you can loop (typically Do-While) an entire folder to return all its folders and subfolders until Dir returns empty. In the loop you can check for your pattern match, if it matches (eg with the Like operator) recursively call the same routine passing the found folder as the parent folder for the next call, and so on. Also pass the folder level incrementing with +1 (be sure to do that ByVal) and say a string array for each of your folder generations to compare with in the given "level". Also I don't follow what you mean or your objective when you say you "provide these paths". In the second example would "C:\FoDder1\Folder2\Folder3\" be correct or incorrect, and if incorrect why. What are you actually trying to do. You might also use FSO which is perhaps more intuitive, though generally I prefer Dir. Regards, Peter T "Charlotte E." wrote in message ... How to find/get the FULL path from a path with pattern recognition??? If I provide these paths: C:\Folder1\Folder2\Folder3\ C:\Fo?der1\Folder2\Folder3\ C:\Folder1\Fol*der2\Folder3\ C:\Folder1\Folde?2\?older3\ C:\Fol?er1\Fo*der2\Fo*der3\ C:\Fol*der1\Folder2\Fold?er3\ ...I would like to retreive C:\Folder1\Folder2\Folder3\ ...in all cases? Apparrently DIR() only give the last folder, and only if the middle folder doesn't contain a pattern char! FileSystemObject won't return and full path if given a pattern path! API 'GetLongPathName' fails completely if using pattern chars! What am I missing?!? ..and if I'm putting in the short name extender (~) everything goes south How to get the FULL path, no matter what pattern chars I have included in the path??? Thanks, CE |
Path from path???
I agree with Peter that using the 'Like' operator in a 'drill-down'
loop is probably the easiest way to go! Perhaps you may find Karl's 'DirDrill' example worth modifying to that end, so it only returns Dirs... http://vb.mvps.org/samples/DirDrill/ I also have a FSO version of this if you're interested! -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
Path from path???
Only lightly tested
Sub test() Dim i As Long, j As Long Dim cnt As Long Dim arrS(1 To 6), aPath Dim ac(1 To 6) As Collection arrS(1) = "C:\Folder1\Folder2\Folder3\" arrS(2) = "C:\Fo?der1\Folder2\Folder3\" arrS(3) = "C:\Folder1\Fol*der2\Folder3\" arrS(4) = "C:\Folder1\Folde?2\?older3\" arrS(5) = "C:\Fol?er1\Fo*der2\Fo*der3\" arrS(6) = "C:\Fol*der1\Folder2\Fold?er3\" For i = 1 To 6 aPath = arrS(i) aPath = Split(aPath, "\") cnt = UBound(aPath) Set ac(i) = New Collection If Len(aPath(UBound(aPath))) = 0 Then cnt = cnt - 1 recDirTest aPath(0), aPath, ac(i), 1, cnt Next For i = 1 To 6 For j = 1 To ac(i).Count Debug.Print i; j, ac(i)(j) Next Next End Sub Sub recDirTest(sPath, arrPath, col As Collection, _ ByVal level As Long, last As Long) Dim i As Long Dim nAttr As Long Dim sFF As String Dim cPaths As Collection Call Dir("nul") If Right$(sPath, 1) < "\" Then sPath = sPath & "\" sFF = Dir$(sPath, vbDirectory) Do While Len(sFF) nAttr = GetAttr(sPath & sFF) If (nAttr And vbDirectory) = vbDirectory Then If sFF Like arrPath(level) Then If level = last Then col.Add sPath & sFF ElseIf level < last Then If cPaths Is Nothing Then Set cPaths = New Collection cPaths.Add sPath & sFF End If End If End If sFF = Dir$(, vbDirectory) Loop If Not cPaths Is Nothing Then For i = 1 To cPaths.Count recDirTest cPaths(i), arrPath, col, level + 1, last Next End If End Sub BTW, you can't return C:\Folder1\Folder2\Folder3\ from your 6th string Regards, Peter T "Charlotte E." wrote in message ... What are you actually trying to do. I need to know what full path a given pattern actually finds... ..no matter which or how many or where pattern chars are included. CE "Peter T" wrote in message ... Not sure where you get the idea Dir only gives the last folder. Dir works in two ways, you can check if a particular folder (or file) exists, or you can loop (typically Do-While) an entire folder to return all its folders and subfolders until Dir returns empty. In the loop you can check for your pattern match, if it matches (eg with the Like operator) recursively call the same routine passing the found folder as the parent folder for the next call, and so on. Also pass the folder level incrementing with +1 (be sure to do that ByVal) and say a string array for each of your folder generations to compare with in the given "level". Also I don't follow what you mean or your objective when you say you "provide these paths". In the second example would "C:\FoDder1\Folder2\Folder3\" be correct or incorrect, and if incorrect why. What are you actually trying to do. You might also use FSO which is perhaps more intuitive, though generally I prefer Dir. Regards, Peter T "Charlotte E." wrote in message ... How to find/get the FULL path from a path with pattern recognition??? If I provide these paths: C:\Folder1\Folder2\Folder3\ C:\Fo?der1\Folder2\Folder3\ C:\Folder1\Fol*der2\Folder3\ C:\Folder1\Folde?2\?older3\ C:\Fol?er1\Fo*der2\Fo*der3\ C:\Fol*der1\Folder2\Fold?er3\ ...I would like to retreive C:\Folder1\Folder2\Folder3\ ...in all cases? Apparrently DIR() only give the last folder, and only if the middle folder doesn't contain a pattern char! FileSystemObject won't return and full path if given a pattern path! API 'GetLongPathName' fails completely if using pattern chars! What am I missing?!? ..and if I'm putting in the short name extender (~) everything goes south How to get the FULL path, no matter what pattern chars I have included in the path??? Thanks, CE |
Path from path???
Hi Peter and Garry,
Thanks to both of you for your input and code examples -and you're absolutely right: A loop down the path is the way to go... ....I just didn't think of this because, I was so focused on a method to return the path in one quick function. Sometimes you cannot see the forest because of all them trees :-) I got it working, so thank you to both of you... CE "Charlotte E." wrote in message ... How to find/get the FULL path from a path with pattern recognition??? If I provide these paths: C:\Folder1\Folder2\Folder3\ C:\Fo?der1\Folder2\Folder3\ C:\Folder1\Fol*der2\Folder3\ C:\Folder1\Folde?2\?older3\ C:\Fol?er1\Fo*der2\Fo*der3\ C:\Fol*der1\Folder2\Fold?er3\ ...I would like to retreive C:\Folder1\Folder2\Folder3\ ...in all cases? Apparrently DIR() only give the last folder, and only if the middle folder doesn't contain a pattern char! FileSystemObject won't return and full path if given a pattern path! API 'GetLongPathName' fails completely if using pattern chars! What am I missing?!? ..and if I'm putting in the short name extender (~) everything goes south How to get the FULL path, no matter what pattern chars I have included in the path??? Thanks, CE |
Path from path???
Hi Peter and Garry,
Thanks to both of you for your input and code examples -and you're absolutely right: A loop down the path is the way to go... ...I just didn't think of this because, I was so focused on a method to return the path in one quick function. Sometimes you cannot see the forest because of all them trees :-) I got it working, so thank you to both of you... CE That's great! Thanks for the feedback... -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
All times are GMT +1. The time now is 03:07 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com