| View previous topic :: View next topic |
| Author |
Message |
Josh Litherland Newbie

Joined: 23 Mar 2009 Posts: 3
|
Posted: Mon Mar 23, 2009 3:44 pm Post subject: (SOLVED) Recursive directory enumeration in Basic ? |
|
|
I'm trying to write a directory traversal macro, and it seems that the "Dir" call I'm making isn't interacting nicely with the recursive calling.
Here's a cut-down version of what I'm trying to do, which illustrates the problem:
| Code: |
sub direnum()
direnum_recurse("C:\")
end sub
sub direnum_recurse(whatsub)
i=Dir(whatsub, 16)
do while i <> ""
if ( i <> "." AND i <> ".." ) then
msgbox("Found a dir: " + whatsub + i)
direnum_recurse(whatsub + i + "\")
end if
i=Dir
loop
end sub
|
I would expect that code to recursively list _all_ directories underneath C:\, but instead it terminates after traversing the full depth of the first directory it finds in each level. It seems that once the 'i <> ""' test fails the first time, it falls all the way back out to the top level caller.
Can anyone provide any insight into what I'm doing wrong, or suggest another way to recursively scan a folder?
Last edited by Josh Litherland on Mon Apr 06, 2009 9:47 am; edited 1 time in total |
|
| Back to top |
|
 |
Kim Randell Newbie

Joined: 10 Mar 2009 Posts: 3
|
Posted: Mon Apr 06, 2009 8:25 am Post subject: |
|
|
I just ran into this issue myself after working from the StarOffice Basic Programmer's Guide. I think this thread solves the problem with an alternative directory access technique:
http://www.oooforum.org/forum/viewtopic.phtml?t=7631 |
|
| Back to top |
|
 |
Josh Litherland Newbie

Joined: 23 Mar 2009 Posts: 3
|
Posted: Mon Apr 06, 2009 8:38 am Post subject: |
|
|
This looks very promising! I'll give it a shot and report back. Thanks! |
|
| Back to top |
|
 |
Josh Litherland Newbie

Joined: 23 Mar 2009 Posts: 3
|
Posted: Mon Apr 06, 2009 9:46 am Post subject: |
|
|
| That worked _perfectly_. Thanks! |
|
| Back to top |
|
 |
|