From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mike Mattie Newsgroups: gmane.emacs.help Subject: Re: traverse a directory Date: Tue, 1 Jan 2008 21:43:15 -0800 Message-ID: <20080101214315.442b1509@reforged> References: <5f20a79c-c1fc-4853-b55f-657f6d66f0e9@l6g2000prm.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0082934319==" X-Trace: ger.gmane.org 1199252705 5125 80.91.229.12 (2 Jan 2008 05:45:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 2 Jan 2008 05:45:05 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jan 02 06:45:24 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1J9wPp-0002rG-Sw for geh-help-gnu-emacs@m.gmane.org; Wed, 02 Jan 2008 06:45:22 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J9wPT-0001J4-Nc for geh-help-gnu-emacs@m.gmane.org; Wed, 02 Jan 2008 00:44:59 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1J9wP7-0001Gz-7i for help-gnu-emacs@gnu.org; Wed, 02 Jan 2008 00:44:37 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1J9wP6-0001GJ-HW for help-gnu-emacs@gnu.org; Wed, 02 Jan 2008 00:44:36 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J9wP6-0001GG-C2 for help-gnu-emacs@gnu.org; Wed, 02 Jan 2008 00:44:36 -0500 Original-Received: from wa-out-1112.google.com ([209.85.146.176]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1J9wP5-0000Ea-St for help-gnu-emacs@gnu.org; Wed, 02 Jan 2008 00:44:36 -0500 Original-Received: by wa-out-1112.google.com with SMTP id k34so8735018wah.10 for ; Tue, 01 Jan 2008 21:44:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:subject:message-id:in-reply-to:references:x-mailer:mime-version:content-type; bh=PqH8N10vWmGP3LuvM8qjGfKC2NG74pHOuRik1SW7tQY=; b=HG0TadhilcHVUScwwoEGYY4YmoHCkGP6XCR2p72oZpSPKH1u6Dq5RzW0PgqscJFMO5XmHz2GB3ebk08XS0r6CBt/uNDULjUHzjUNbUB+UPKfy8ML0REnwNq4HhgjHcHthCwqHZmJYxNClU3FXiehVB7jHVPSdNNusy/l824KasY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:in-reply-to:references:x-mailer:mime-version:content-type; b=hvJpsfqarf1UiJIdyfjcjT95KCKCsXuEzlruMzDHeniAgm1p6vA9rMqDMajoJikLkB+j7M1Ak0iGBmcTFiaV0O1JjuEofGPTB/dnASGcfXsSm/kunnlWDazCEGnUWGo2J+/zXrGLJq6CvRKVDYO4aVYySXMjLA3aKPYSL/AFCOs= Original-Received: by 10.114.166.1 with SMTP id o1mr14939061wae.71.1199252674899; Tue, 01 Jan 2008 21:44:34 -0800 (PST) Original-Received: from reforged ( [71.217.198.62]) by mx.google.com with ESMTPS id j38sm5667886waf.54.2008.01.01.21.44.32 (version=SSLv3 cipher=OTHER); Tue, 01 Jan 2008 21:44:33 -0800 (PST) In-Reply-To: <5f20a79c-c1fc-4853-b55f-657f6d66f0e9@l6g2000prm.googlegroups.com> X-Mailer: Claws Mail 3.0.2 (GTK+ 2.12.1; i686-pc-linux-gnu) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:50432 Archived-At: --===============0082934319== Content-Type: multipart/signed; boundary="Sig_/PCstwSkxcFAMCnTvaGGW0=9"; protocol="application/pgp-signature"; micalg=PGP-SHA1 --Sig_/PCstwSkxcFAMCnTvaGGW0=9 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, 1 Jan 2008 08:51:33 -0800 (PST) Xah Lee wrote: > if i want to recurse into a directory, do i have to write my own? >=20 > e.g. i want to apply a file processing function to all files in a dir > and subdirs. Somethnig like >=20 > (apply 'process-my-file "/Users/xah/emacs/" "\.html$") >=20 > I noticed that directory-files only list the dir file. Someone told me > there's a directory-files-recur but that doesn't seems to be in emacs. >=20 > thx in advance. here is something kinda related that I recently hacked up. I needed to be a= ble to filter the results of a directory list. The first hack started off as a pla= in defun but I encountered variations so I made a macro. it may duplicate exis= ting emacs code. the elisp-in-path defun shows how the form is used. It's uncommented, and relies upon map-filter-nil which needs to be non-recursive for general use. It is pretty easy to extend for filtering on either the path or the mode st= ring. Writing a general tree recursion is trivial, it shouldn't even be file spec= ific. this defun may help tailor such a recursion towards a fs tree. (defun filter-ls-attributes ( filter-form ) "implement the various attribute filters for the filter-ls form" (lexical-let ((attr-name (symbol-name (car filter-form))) (attr-match (cadr filter-form))) (cond ((string-equal "type" attr-name) (list 'char-equal attr-match '(aref= (cdr path-pair) 0))) ((string-equal "path" attr-name) (list 'string-match-p attr-match '(c= ar path-pair))) ;; error path ))) (defmacro filter-ls (path path-type &rest filters) "a form for flexibly filtering the result of listing a directory with att= ributes" `(apply 'map-filter-nil (lambda ( path-pair ) (if ,(cons 'and (mapcar 'filter-ls-attributes filters)) (car path-pair))) ;; reduce the attributes to a pair of the path, and the mode string (mapcar (lambda ( attr-list ) (cons (car attr-list) (nth 9 attr-list))) ;; get the list of files. (directory-files-and-attributes ,path ,path-type)) )) ;; path-type is t absolute, nil relative. (defun elisp-in-path ( path path-type ) "return a list of elisp files in the path" (filter-ls path path-type (type ?-) (path "\\.el$"))) P.S here is map-filter-nil. use at your own risk. (defun map-filter-nil ( func &rest seq ) "map-filter-nil. apply the function to the arguements ala mapcar. Filter any nil elements of the sequence before the function is applied, and after the function is applied." (if (car seq) (let ((result (funcall func (car seq)))) (if result (cons result (apply 'map-filter-nil func (cdr seq))) (apply 'map-filter-nil func (cdr seq)) )) (if (cdr seq) (apply 'map-filter-nil func (cdr seq))) )) > Xah > xah@xahlee.org > =E2=88=91 http://xahlee.org/ >=20 > _______________________________________________ > help-gnu-emacs mailing list > help-gnu-emacs@gnu.org > http://lists.gnu.org/mailman/listinfo/help-gnu-emacs --Sig_/PCstwSkxcFAMCnTvaGGW0=9 Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQFHeyR1dfRchrkBInkRArybAKDm8ydPWmxgGY10JGZ8tl123Nm+hwCgq5il v0weFSb+7yLPrniCRmluCU0= =nthE -----END PGP SIGNATURE----- --Sig_/PCstwSkxcFAMCnTvaGGW0=9-- --===============0082934319== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ help-gnu-emacs mailing list help-gnu-emacs@gnu.org http://lists.gnu.org/mailman/listinfo/help-gnu-emacs --===============0082934319==--