JamesMcS
Keyboard-Chair Interface
- Local time
- Today, 22:07
- Joined
- Sep 7, 2009
- Messages
- 1,819
Afternoon all!! Hoping you can point me in the right direction here....
So - I've got this bit of code. It's supposed to read the paths of folders and subfolders into an array, which I'm then going to cycle through with another Dir command to find MDBs and compact them.
The process is:
Call the sub with the starting folder as an argument, eg "C:\Temp"
Dir goes through files, looking for directories and ignoring . and ..
Finds a directory - calls itself again to repeat the process, appending paths of directories to the arrray as it goes.
It seems to work OK until it returns to the first instance of the sub after calling itself the first time. The Dir() command at the bottom returns "Invalid Procedure Call or Argument", which I take to mean that Dir is not looking where it was before the routine was called again... any ideas how I can get around this? It seems like such a simple piece of code to get the folder list, shame to have to expand it dramatically.....
So - I've got this bit of code. It's supposed to read the paths of folders and subfolders into an array, which I'm then going to cycle through with another Dir command to find MDBs and compact them.
The process is:
Call the sub with the starting folder as an argument, eg "C:\Temp"
Dir goes through files, looking for directories and ignoring . and ..
Finds a directory - calls itself again to repeat the process, appending paths of directories to the arrray as it goes.
It seems to work OK until it returns to the first instance of the sub after calling itself the first time. The Dir() command at the bottom returns "Invalid Procedure Call or Argument", which I take to mean that Dir is not looking where it was before the routine was called again... any ideas how I can get around this? It seems like such a simple piece of code to get the folder list, shame to have to expand it dramatically.....
Code:
Sub List_SubDirs(UserPath As String)
Dim SubDirList, Sub_Sub As String
Dim DirArrayPos As Integer
Call Init_Globals
DirArrayPos = 1
'Collect Root Subdirectory Names into Array
If DirArray(DirArrayPos) <> "" Then
SubDirList = Dir(DirArray(DirArrayPos) & "\*.*", vbDirectory)
Else
SubDirList = Dir(UserPath & "\*.*", vbDirectory)
End If
Do While SubDirList <> ""
If GetAttr(UserPath & "\" & SubDirList) = vbDirectory And SubDirList <> "." And SubDirList <> ".." Then
DirArray(DirArrayPos) = UserPath & "\" & SubDirList
Sub_Sub = DirArray(DirArrayPos)
DirArrayPos = DirArrayPos + 1
Call List_SubDirs(Sub_Sub)
End If
SubDirList = Dir
Loop
End Sub