From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Neil Jerram" Newsgroups: gmane.lisp.guile.user Subject: Re: Fail stating a file not in current folder Date: Wed, 17 Sep 2008 09:59:24 +0100 Message-ID: <49dd78620809170159j4d962c0eu3db153cf667385c7@mail.gmail.com> References: <200809171006.30175.jzu@imtf.ch> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1221641987 19182 80.91.229.12 (17 Sep 2008 08:59:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 17 Sep 2008 08:59:47 +0000 (UTC) Cc: guile-user@gnu.org To: "zulian jc" Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Sep 17 11:00:44 2008 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Kfsto-0003yM-OW for guile-user@m.gmane.org; Wed, 17 Sep 2008 11:00:37 +0200 Original-Received: from localhost ([127.0.0.1]:54452 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kfssn-0001ca-LR for guile-user@m.gmane.org; Wed, 17 Sep 2008 04:59:33 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kfssi-0001cJ-QG for guile-user@gnu.org; Wed, 17 Sep 2008 04:59:28 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kfssg-0001c3-VL for guile-user@gnu.org; Wed, 17 Sep 2008 04:59:28 -0400 Original-Received: from [199.232.76.173] (port=36849 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kfssg-0001c0-Rr for guile-user@gnu.org; Wed, 17 Sep 2008 04:59:26 -0400 Original-Received: from wa-out-1112.google.com ([209.85.146.178]:54051) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Kfssg-0002Ih-Fq for guile-user@gnu.org; Wed, 17 Sep 2008 04:59:26 -0400 Original-Received: by wa-out-1112.google.com with SMTP id m34so1953033wag.10 for ; Wed, 17 Sep 2008 01:59:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=JP99O+RYLmSTakIOdb1+hdi+Sd7y4C/sCLupjt0RJNs=; b=uWOg3KlDvARy/1PFMuxD9dlV18bsbkENImWsD7GTBsvOJ1QWjt14Kjba1nT/iW4Z8X ejjQRWOLWOotHfYMsbEIu1xaWZZ+sAS0BmWgYg6kcvjWa2JlwFHeDA3mIYLWnsGaQJxw 4GDA2BHaIXkSfvtaQ9ANZcdG9Fel2WWV5qUFQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=Vo91tkXXikDBIlSmC6btTkXha4jqdhczunpo9FMuYfb1xXv3nVdNmjnABxeLJuE9oC 3FXpYGa9sMEblgr54o34y9iFMhwtrxvH98L/OTgVnuj/0v99uas5c0nj52ER04PPa9sy ZhxGXWzGblXtog0pNuBe3RsYrnL8HvnnzgYN4= Original-Received: by 10.114.200.2 with SMTP id x2mr1811530waf.79.1221641964649; Wed, 17 Sep 2008 01:59:24 -0700 (PDT) Original-Received: by 10.114.197.8 with HTTP; Wed, 17 Sep 2008 01:59:24 -0700 (PDT) In-Reply-To: <200809171006.30175.jzu@imtf.ch> Content-Disposition: inline X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6771 Archived-At: 2008/9/17 zulian jc : > 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