Re: Quick question about SRFI-170 directory-files Lassi Kortela 29 Jul 2019 18:31 UTC

> Gambit has an open-directory procedure that returns a port whose elements, obtained with read, are the files in the directory.  This prevents the memory usage problem of directory-files on large directories.  You can view this as a wrapper around opendir/readdir/closedir (and it is actually implemented that way).
>
> Marc
>
>> (let ((dir (open-directory "examples")))
>      (let loop ()
>        (let ((x (read dir)))
>          (if (not (eof-object? x))
>              (begin
>                (pretty-print x)
>                (loop))
>              (close-port dir)))))
> "misc"
> "makefile"
> "web-server"
> "tcltk"

That's cool. So you read it with 'read' like a Scheme port and it
returns strings.

A portable way to do the same nowadays might be SRFI 158 generators:

(directory-generator "examples")