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