I was looking to traverse the directory tree on the web, but the code I've seen is usually in excess of 50 lines, whereas other languages do this in five lines. Before I dedicate two days to figure it out, I made my own, which is almost there, but I have two problems with it
I'm trying to use pointer as a global variable, but in the produce subroutine, it makes its own pointer variable. Do I have to declare global pointer like in php?
When I hit file=Dir(""), it returns the same exact file it's already on. When I do file = Dir I get an error Invalid prodedure call or argument as if it forgot the items I loaded into it in the first place
I've also seen a lot of this to check if its a directory:
GetAttr(something, vbDirectory) And vbDirectory
why so difficult? Doesnt' GetAttr just naturally return the attribute, which should be vbDirectory?
Code:
Public pointer As Range
Sub init()
Set pointer = Worksheets("Sheet1").Range("A1")
mypath = "l:\CRATING\CUSTOMERS\Martin Customers"
produce (mypath)
End Sub
Sub produce(mypath)
file = Dir(mypath & "\*", vbNormal Or vbDirectory)
Do While file <> ""
If Not (file = "." Or file = "..") Then
If GetAttr(mypath & "\" & file) = vbDirectory Then
produce (mypath & "\" & file)
Else
pointer.Value = file
pointer = pointer.Offset(1, 0)
End If
End If
file = Dir("")
Loop
End Sub
I'm trying to use pointer as a global variable, but in the produce subroutine, it makes its own pointer variable. Do I have to declare global pointer like in php?
When I hit file=Dir(""), it returns the same exact file it's already on. When I do file = Dir I get an error Invalid prodedure call or argument as if it forgot the items I loaded into it in the first place
I've also seen a lot of this to check if its a directory:
GetAttr(something, vbDirectory) And vbDirectory
why so difficult? Doesnt' GetAttr just naturally return the attribute, which should be vbDirectory?