Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #16  
Old 07-26-2005, 09:30 AM
ph8 ph8 is offline
Registered User
 
Join Date: 13 Feb 2005
Posts: 66
ph8 is becoming part of the community

Please Register to Remove these Ads

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:

Code:
Sub 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
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 unsuccesfull

Code:
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
Please, any help is appreciated.
Reply With Quote
  #17  
Old 07-28-2005, 02:54 AM
ph8 ph8 is offline
Registered User
 
Join Date: 13 Feb 2005
Posts: 66
ph8 is becoming part of the community
Friendly and Shameless Bump. I hope you haven't given up on me just yet Bob Phillips

Again, any help would be greatly appreciated.
Reply With Quote
  #18  
Old 08-02-2005, 02:05 PM
Bob Phillips
Guest
 
Posts: n/a
Re: Recursive Function + File searching to return path

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
>



Reply With Quote
  #19  
Old 08-03-2005, 09:21 AM
ph8 ph8 is offline
Registered User
 
Join Date: 13 Feb 2005
Posts: 66
ph8 is becoming part of the community
Quote:
Originally Posted by Bob Phillips
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.
Reply With Quote
  #20  
Old 08-03-2005, 07:05 PM
Bob Phillips
Guest
 
Posts: n/a
Re: Recursive Function + File searching to return path

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
>



Reply With Quote
  #21  
Old 08-05-2005, 03:19 AM
ph8 ph8 is offline
Registered User
 
Join Date: 13 Feb 2005
Posts: 66
ph8 is becoming part of the community
Sounds good Bob, I look forward to your next post.

v/r
-Eddie
Reply With Quote
  #22  
Old 08-08-2005, 02:40 AM
ph8 ph8 is offline
Registered User
 
Join Date: 13 Feb 2005
Posts: 66
ph8 is becoming part of the community
Friendly Bump for Bob
Reply With Quote
  #23  
Old 08-11-2005, 05:36 AM
ph8 ph8 is offline
Registered User
 
Join Date: 13 Feb 2005
Posts: 66
ph8 is becoming part of the community
Please, this project is so close to being finished, I could really use your help again, Bob -- or anyone willing to provide assistance.
Reply With Quote
  #24  
Old 09-15-2005, 10:15 AM
ph8 ph8 is offline
Registered User
 
Join Date: 13 Feb 2005
Posts: 66
ph8 is becoming part of the community
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 .
Reply With Quote
  #25  
Old 10-14-2005, 03:45 AM
ph8 ph8 is offline
Registered User
 
Join Date: 13 Feb 2005
Posts: 66
ph8 is becoming part of the community
Bumping this thread out of ancient history. Maybe Bob will find it this time...
Reply With Quote


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump