OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

(SOLVED) Recursive directory enumeration in Basic ?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Josh Litherland
Newbie
Newbie


Joined: 23 Mar 2009
Posts: 3

PostPosted: Mon Mar 23, 2009 3:44 pm    Post subject: (SOLVED) Recursive directory enumeration in Basic ? Reply with quote

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
View user's profile Send private message
Kim Randell
Newbie
Newbie


Joined: 10 Mar 2009
Posts: 3

PostPosted: Mon Apr 06, 2009 8:25 am    Post subject: Reply with quote

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
View user's profile Send private message
Josh Litherland
Newbie
Newbie


Joined: 23 Mar 2009
Posts: 3

PostPosted: Mon Apr 06, 2009 8:38 am    Post subject: Reply with quote

Kim Randell wrote:
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


This looks very promising! I'll give it a shot and report back. Thanks!
Back to top
View user's profile Send private message
Josh Litherland
Newbie
Newbie


Joined: 23 Mar 2009
Posts: 3

PostPosted: Mon Apr 06, 2009 9:46 am    Post subject: Reply with quote

That worked _perfectly_. Thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group