unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: guile-devel@gnu.org
Subject: Re: [PATCH] Add "scandir" procedure
Date: Tue, 30 Aug 2011 18:06:39 +0200	[thread overview]
Message-ID: <8762lehoj4.fsf@gnu.org> (raw)
In-Reply-To: 1314475521.3143.47.camel@Renee-desktop

Hi!

nalaginrut <nalaginrut@gmail.com> 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’.




  reply	other threads:[~2011-08-30 16:06 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-27 20:05 [PATCH] Add "scandir" procedure nalaginrut
2011-08-30 16:06 ` Ludovic Courtès [this message]
2011-09-01  4:46   ` Nala Ginrut
2011-09-01 12:12     ` Ludovic Courtès
2011-09-01 16:05       ` Nala Ginrut
2011-09-01 21:01         ` Ludovic Courtès
     [not found]           ` <CAPjoZof=iV57JP4-HgFjGTbMnaa9ex_QfP17Mn12j3XE3GxPSA@mail.gmail.com>
     [not found]             ` <8739gfuxky.fsf@gnu.org>
2011-09-02 11:38               ` Nala Ginrut
2011-09-02 12:14                 ` Ludovic Courtès
2011-12-06 11:52   ` Andy Wingo
2011-12-10 14:52     ` Ludovic Courtès
2011-12-10 15:37       ` Andy Wingo
2011-12-10 19:05         ` Ludovic Courtès
2011-12-14  0:21         ` Ludovic Courtès
2012-01-08 15:22           ` Ludovic Courtès
2011-12-18 20:30 ` Ludovic Courtès
2011-12-19 19:20   ` Nala Ginrut
2011-12-19 21:38     ` Ludovic Courtès
2011-12-20  3:23       ` Nala Ginrut
2011-12-20  3:25         ` Nala Ginrut
2011-12-20 12:03           ` Ludovic Courtès
  -- strict thread matches above, loose matches on Subject: below --
2011-08-27 20:18 Nala Ginrut
2011-09-02  1:00 Nala Ginrut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8762lehoj4.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).