[REBOL] Re: Acquiring sub-dir contents
From: ryanc:iesco-dms at: 11-Oct-2001 16:28
Hi Donald,
mine only read the contents of each subdirectory in the current directory, so it
could have overlooked the files you were trying to read. Christopher's recursive
version should have produced results no matter what you threw at it.
BTW you can reduce your code to this just by removing the temp variables by
feeding functions into one another...
; append each directory list into block
all-files: COPY []
FOREACH drawer READ read-drawer [
CHANGE-DIR JOIN read-drawer drawer
APPEND all-files READ %.
]
And a little more by changing the path and not the directory...
; append each directory list into block
all-files: COPY []
FOREACH drawer READ read-drawer [
APPEND all-files READ JOIN read-drawer drawer
]
And to stablize things...
; append each directory list into block
all-files: COPY []
FOREACH drawer READ read-drawer [
if dir? JOIN read-drawer drawer [
APPEND all-files READ JOIN read-drawer drawer
]
]
--Ryan
Donald Dalley wrote:
> Hello, Ryan & Christopher:
>
> Thanks to you both, for your ideas.
>
> On 04-Oct-01, Ryan Cole wrote:
>
> > Does this do what you need?
>
> > get-sub-files: does [
> > files: copy []
> > foreach item read %. [ if dir? item [append files read item] ]
> > ]
>
> Not on its own - I tried it "as is", after getting variable names synced, but
> it didn't work. Having said that, I didn't pursue it, to find out >why< it
> didn't work for me.
>
> The following is what I ended up using:
>
> ; get top drawer-list
> drawer-list: READ read-drawer
> cur-files: COPY []
> all-files: COPY []
>
> ; append each directory list into block
> FOREACH drawer drawer-list [
> new-path: JOIN read-drawer drawer
> CHANGE-DIR new-path
> cur-files: READ %.
> all-files: APPEND all-files cur-files
> ]
>
> It reads the top drawer, for that drawer's list of directories, builds a new
> path for each sub-directory (there's only one sub level), changes its local
> path, then reads each sub-directory, appending its file names into a block.
>
> It's not smart, in the sense that it only deals with directories, but it does
> what I need, for now. A file in the top drawer will stop the run, though, so
> it most definitely can be improved. Making it into a function may be the next
> step, but I'll use it this way, for a while, first.
>
> --
>
> ---===///||| Donald Dalley |||\\\===---
> The World of AmiBroker Support
> http://webhome.idirect.com/~ddalley
> UIN/ICQ#: 65203020
>
> > --Ryan
>
> > Ryan Cole
> > Programmer Analyst
> > www.iesco-dms.com
> > 707-468-5400
>
> > Donald Dalley wrote:
>
> > > Hi, REBOLs:
> > >
> > > Is there a small, simple method (or function) of getting just the file
> names
> > > within a set of sub-drawers? I am having trouble efficiently applying what
> > > little directory code there is, in the web database.
> > >
> > > The parent directory has a set of drawers named (-, A, B, C..., 1, 2,
> 3...),
> > > but the code should work universally with any name set. The goal, of
> course,
> > > is to get only the file names within the drawer set, not the drawer names.
>
> --
> To unsubscribe from this list, please send an email to
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
Ryan Cole
Programmer Analyst
www.iesco-dms.com
707-468-5400