Maybe its something that I am doing wrong. But I still can't get it to work as intended. Here is the code after I make my modifications to it. In truth, all I do is shorten the display of the output and have the 'backslash' search feature only look in the truncated path instead.
It still gives the flawed output you were talking about:
The code here (which is the same one Bob Phillips first posted) displays the files in the correct order, just the way it is displayed isn't entirelly what I want. I have been trying for the life of me to try and interpret this code but I can't seem to fully understand it. Most likely because there are so many 'new' commands to me in the code. Regardless, wouldn't it be simplest to just modify this code to display the output the way I requested? I have been trying do this myself, but the results were unsuccesfullSub thenextph8() Dim sStartFolder As String Dim iCtr As Long Dim iLevel As Long Dim iBaseLevel As Long Dim sh As Worksheet Dim iPath sStartFolder = ThisWorkbook.path iBaseLevel = Len(sStartFolder) - Len(Replace(sStartFolder, "\", "")) With Application.FileSearch .NewSearch .LookIn = sStartFolder .SearchSubFolders = True .FileType = msoFileTypeExcelWorkbooks If .Execute > 0 Then On Error Resume Next Set sh = Worksheets("Files") On Error GoTo 0 If Not sh Is Nothing Then sh.Cells.ClearContents Else Worksheets.Add.Name = "Files" Set sh = ActiveSheet End If sh.Cells(1, 1) = sStartFolder sh.Cells(1, 2) = 1 For iCtr = 1 To .FoundFiles.Count iPath = Replace(.FoundFiles(iCtr), ThisWorkbook.path, "") iLevel = Len(iPath) - Len(Replace(iPath, "\", "")) sh.Cells(iCtr + 1, 1) = iPath sh.Cells(iCtr + 1, 2).Value = iLevel Next iCtr End If End With End Sub
Please, any help is appreciated.Option Explicit Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _ Alias "SHGetPathFromIDListA" _ (ByVal pidl As Long, _ ByVal pszPath As String) As Long Private Declare Function SHBrowseForFolder Lib "shell32.dll" _ Alias "SHBrowseForFolderA" _ (lpBrowseInfo As BROWSEINFO) As Long Private Type BROWSEINFO hOwner As Long pidlRoot As Long pszDisplayName As String lpszTitle As String ulFlags As Long lpfn As Long lParam As Long iImage As Long End Type Private FSO As Object Private cnt As Long Private arfiles Private level As Long Sub Folders() Dim i As Long Dim sFolder As String Dim sh As Worksheet Set FSO = CreateObject("Scripting.FileSystemObject") arfiles = Array() cnt = -1 level = 1 sFolder = GetFolder ReDim arfiles(1, 0) If sFolder <> "" Then SelectFiles sFolder On Error Resume Next Set sh = Worksheets("Files") On Error GoTo 0 If Not sh Is Nothing Then sh.Cells.ClearContents Else Worksheets.Add.Name = "Files" End If With ActiveSheet For i = LBound(arfiles, 2) To UBound(arfiles, 2) .Hyperlinks.Add Anchor:=.Cells(i + 1, arfiles(1, i)), _ Address:=arfiles(0, i), _ TextToDisplay:=arfiles(0, i) Next .Columns("A:Z").EntireColumn.AutoFit End With End If End Sub '-----------------------------*------------------------------*------------ Sub SelectFiles(Optional sPath As String) '-----------------------------*------------------------------*------------ Dim fldr As Object Dim Folder As Object Dim file As Object Dim Files As Object If sPath = "" Then Set FSO = CreateObject("Scripting.FileSystemObject") sPath = GetFolder End If Set Folder = FSO.GetFolder(sPath) Set Files = Folder.Files For Each file In Files cnt = cnt + 1 ReDim Preserve arfiles(1, cnt) arfiles(0, cnt) = Folder.path & "\" & file.Name arfiles(1, cnt) = level Next file level = level + 1 For Each fldr In Folder.Subfolders SelectFiles fldr.path Next level = level - 1 End Sub '-----------------------------*------------------------------*-- Function GetFolder(Optional ByVal Name As String = "Select a folder.") As String '-----------------------------*------------------------------*-- Dim bInfo As BROWSEINFO Dim path As String Dim oDialog As Long bInfo.pidlRoot = 0& 'Root folder = Desktop bInfo.lpszTitle = Name bInfo.ulFlags = &H1 'Type of directory to oDialog = SHBrowseForFolder(bInfo) 'display the dialog 'Parse the result path = Space$(512) GetFolder = "" If SHGetPathFromIDList(ByVal oDialog, ByVal path) Then GetFolder = Left(path, InStr(path, Chr$(0)) - 1) End If End Function
Friendly and Shameless Bump. I hope you haven't given up on me just yet Bob Phillips
Again, any help would be greatly appreciated.
Sorry mate, only just seen this follow-up.
What is not happening that you want to happen?
--
HTH
RP
(remove nothere from the email address if mailing direct)
"ph8" <ph8.1svbfe_1122534380.174@excelforum-nospam.com> wrote in message
news:ph8.1svbfe_1122534380.174@excelforum-nospam.com...
>
> Friendly and Shameless Bump. I hope you haven't given up on me just yet
> Bob Phillips
>
> Again, any help would be greatly appreciated.
>
>
> --
> ph8
> ------------------------------------------------------------------------
> ph8's Profile:
http://www.excelforum.com/member.php...o&userid=19871
> View this thread: http://www.excelforum.com/showthread...hreadid=387116
>
The longer code is producing the list in the correct order. The shorter code is producing the output correctly, but the order is still skewed. Ideally, I would like the longer code's output in the format of the shorter code's output.Originally Posted by Bob Phillips
Does this make sense?
PS: Thanks for keeping with me. I appreciate it.
ph8,
I need to leave now, but just to let you know I will re-look at this
tomorrow. Hopefully, we will see a conclusion then.
Regards
Bob
"ph8" <ph8.1t71nh_1123082142.9094@excelforum-nospam.com> wrote in message
news:ph8.1t71nh_1123082142.9094@excelforum-nospam.com...
>
> Bob Phillips Wrote:
> > What is not happening that you want to happen?
> >
> The longer code is producing the list in the correct order. The
> shorter code is producing the output correctly, but the order is still
> skewed. Ideally, I would like the longer code's output in the format
> of the shorter code's output.
>
> Does this make sense?
>
> PS: Thanks for keeping with me. I appreciate it.
>
>
> --
> ph8
> ------------------------------------------------------------------------
> ph8's Profile:
http://www.excelforum.com/member.php...o&userid=19871
> View this thread: http://www.excelforum.com/showthread...hreadid=387116
>
Sounds good Bob, I look forward to your next post.
v/r
-Eddie
Friendly Bump for Bob
Please, this project is so close to being finished, I could really use your help again, Bob -- or anyone willing to provide assistance.
I guess Ill post again in hopes of getting Bob's attention one last time. I'll remain optimistic and trust Bob will still get to it as he has told me. Further help would be greatly appreciated Bob.
Bumping this thread out of ancient history. Maybe Bob will find it this time...
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks