* Fail stating a file not in current folder
@ 2008-09-17 8:06 zulian jc
2008-09-17 8:59 ` Neil Jerram
0 siblings, 1 reply; 2+ messages in thread
From: zulian jc @ 2008-09-17 8:06 UTC (permalink / raw
To: guile-user
Hello guile list,
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?
(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?
Thanks in advance for your help,
jc
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Fail stating a file not in current folder
2008-09-17 8:06 Fail stating a file not in current folder zulian jc
@ 2008-09-17 8:59 ` Neil Jerram
0 siblings, 0 replies; 2+ messages in thread
From: Neil Jerram @ 2008-09-17 8:59 UTC (permalink / raw
To: zulian jc; +Cc: guile-user
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-09-17 8:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-17 8:06 Fail stating a file not in current folder zulian jc
2008-09-17 8:59 ` Neil Jerram
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).