unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Neil Jerram" <neiljerram@googlemail.com>
To: "zulian jc" <jzu@imtf.ch>
Cc: guile-user@gnu.org
Subject: Re: Fail stating a file not in current folder
Date: Wed, 17 Sep 2008 09:59:24 +0100	[thread overview]
Message-ID: <49dd78620809170159j4d962c0eu3db153cf667385c7@mail.gmail.com> (raw)
In-Reply-To: <200809171006.30175.jzu@imtf.ch>

2008/9/17 zulian jc <jzu@imtf.ch>:
> Hello guile list,

Hi!

> I am new to guile and scheme so excuse my poor coding. Anyway I am faced with
> a little problem with guile 1.8.1. I am writing a function that collects all
> sub-directory from a given directory. To do this I am using the opendir and
> readdir functions. However it happens that if I am not cd'ing into the
> directory I want to browse, the following function failed. Is that a normal
> behavior?

Yes, because of what you have suggested...

> (define gather-dirs
>  (lambda (path)
>    ;; with the following line commented out the function will fail browsing
>    ;; directories other than the current one
>    ;;(chdir path)
>    (let ((cdir (opendir path))
>          (l '()))
>      (do ((entry (readdir cdir) (readdir cdir)))
>        ((eof-object? entry) l)
>        (if (directory? entry)
>            (set! l (cons entry l)))))))
>
> (define directory?
>  (lambda (x)
>    (eq? (stat:type (stat x)) 'directory)))
>
> Here is the error I get back:
> ERROR: In procedure stat:
> ERROR: No such file or directory: ".bb"
>
> Note: '.bb' is a folder that exist in the folder I want to browse but not in
> the current one. So basicaly 'readdir' and 'opendir' did their job fine but
> when I am trying to stat on the found entry it fails (in the 'directory?'
> function).
>
> Investigating further I saw that 'readdir' just return a string with the name
> of the folder entry, that is a name relative to the folder opened
> by 'opendir'. Say I am browsing '/home/bob' folder then readdir will return
> me as an entry "bin" and not "/home/bob/bin". Hence 'stat' is failing if
> there is no 'bin' folder in current folder. Is that correct?
>
> Now how could one browse a folder and stat on each entry without having to
> change to that folder?

You can use `in-vicinity' to form a relative path name from the
working directory.  Your code above should work if you change the
(directory? entry) call to:

 (directory? (in-vicinity path entry))

Regards,
         Neil




      reply	other threads:[~2008-09-17  8:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-17  8:06 Fail stating a file not in current folder zulian jc
2008-09-17  8:59 ` Neil Jerram [this message]

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=49dd78620809170159j4d962c0eu3db153cf667385c7@mail.gmail.com \
    --to=neiljerram@googlemail.com \
    --cc=guile-user@gnu.org \
    --cc=jzu@imtf.ch \
    /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).