OaklandJim
Well-known Member
- Joined
- Nov 29, 2018
- Messages
- 855
- Office Version
- 365
- Platform
- Windows
Go easy on me. I'm more of a decent hacker using other's code not a programmer. 1st post here.
Tried using recursive code I found based on MS scripting (which I barely understand) to parse directory tree to fill an array with all paths. It seems to be parsing fine as I can tell HOW MANY dirs it found. But I cannot figure out how to use the scripting object to get/stash the paths' NAME. It is close but when I try to use objFile.Path to get the path my sub chokes on it.
In caller I set up objects
' Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'
' Get the top folder
Set objTopFolder = objFSO.GetFolder(sAnchorPath)
Then this sub chokes when I try to access the path names during parsing.
Sub RecursiveTreePaths( _
objFolder As Scripting.Folder, _
ByRef pasDirs() As String)
' scripting object variables
Dim objFile As Scripting.file
Dim objSubFolder As Scripting.Folder
' NEXT array element
Dim iUboundNext As Integer
iUboundNext = UBound(pasDirs) + 1
' Debug.Print "iUboundNext = " & iUboundNext
'FAILS Debug.Print "objFile.Path = " & objFile.Path
' Add another element to the byref param array
' for the directory currently being recorded.
ReDim Preserve pasDirs(iUboundNext)
' put current path into array
'FAILS pasDirs(iUboundNext) = objFile.Path
' recursive parsing of directory tree
For Each objSubFolder In objFolder.SubFolders
Call RecursiveTreePaths(objSubFolder, pasDirs)
Next objSubFolder
End Sub
Tried using recursive code I found based on MS scripting (which I barely understand) to parse directory tree to fill an array with all paths. It seems to be parsing fine as I can tell HOW MANY dirs it found. But I cannot figure out how to use the scripting object to get/stash the paths' NAME. It is close but when I try to use objFile.Path to get the path my sub chokes on it.
In caller I set up objects
' Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'
' Get the top folder
Set objTopFolder = objFSO.GetFolder(sAnchorPath)
Then this sub chokes when I try to access the path names during parsing.
Sub RecursiveTreePaths( _
objFolder As Scripting.Folder, _
ByRef pasDirs() As String)
' scripting object variables
Dim objFile As Scripting.file
Dim objSubFolder As Scripting.Folder
' NEXT array element
Dim iUboundNext As Integer
iUboundNext = UBound(pasDirs) + 1
' Debug.Print "iUboundNext = " & iUboundNext
'FAILS Debug.Print "objFile.Path = " & objFile.Path
' Add another element to the byref param array
' for the directory currently being recorded.
ReDim Preserve pasDirs(iUboundNext)
' put current path into array
'FAILS pasDirs(iUboundNext) = objFile.Path
' recursive parsing of directory tree
For Each objSubFolder In objFolder.SubFolders
Call RecursiveTreePaths(objSubFolder, pasDirs)
Next objSubFolder
End Sub