Hi! nalaginrut <[email protected]> skribis:
> I found there isn't "scandir" in current Guile. And we may use "ftw" to > instead. I guess "ftw" traverse all sub-directoies. Yes, we may use nftw > to filter the level we don't need, but "ftw" seems always traverse all > sub-directories. If my guess is correct, I believe it's too slow for > someone, for a instance, me. :-) I was actually planning to push ‘file-system-fold’, a functional alternative to ‘ftw’, which would be along the lines of this (from <http://git.savannah.gnu.org/cgit/libchop.git/tree/utils/chop-backup#n46>): (define (file-system-fold enter? leaf down up skip init file-name) "Traverse the directory at FILE-NAME, recursively. Enter sub-directories only when (ENTER? PATH STAT RESULT) returns true. When a sub-directory is entered, call (DOWN PATH STAT RESULT), where PATH is the path of the sub-directory and STAT the result of (lstat PATH); when it is left, call (UP PATH STAT RESULT). For each file in a directory, call (LEAF PATH STAT RESULT). Return the result of these successive applications. When ENTER? returns no, call (SKIP PATH STAT RESULT)." ...) I think it would allow you to do what you want, right? Like this: (define (directory-contents file-name) "Return the list of regular files and directories in the directory at FILE-NAME as a list of name/stat pairs." (file-system-fold (lambda (path stat result) ; enter? (eq? path file-name)) alist-cons ; leaf (lambda (path stat result) result) ; down (lambda (path stat result) result) ; up alist-cons ; skip '() file-name)) What do you think? Thanks, Ludo’.
