From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17037 invoked from network); 28 Mar 2004 19:22:08 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 28 Mar 2004 19:22:08 -0000 Received: (qmail 15535 invoked by alias); 28 Mar 2004 19:21:53 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7277 Received: (qmail 15525 invoked from network); 28 Mar 2004 19:21:52 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 28 Mar 2004 19:21:52 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [130.225.247.86] by sunsite.dk (MessageWall 1.0.8) with SMTP; 28 Mar 2004 19:21:52 -0000 Received: (qmail 24651 invoked from network); 28 Mar 2004 19:21:51 -0000 Received: from wbar3.sjo1-4-11-009-147.sjo1.dsl-verizon.net (HELO candle.brasslantern.com) (4.11.9.147) by a.mx.sunsite.dk with SMTP; 28 Mar 2004 19:21:49 -0000 Received: (from schaefer@localhost) by candle.brasslantern.com (8.11.6/8.11.6) id i2SJLlr26161 for zsh-users@sunsite.dk; Sun, 28 Mar 2004 11:21:47 -0800 X-Authentication-Warning: candle.brasslantern.com: schaefer set sender to schaefer@closedmail.com using -f From: Bart Schaefer Message-Id: <1040328192147.ZM26160@candle.brasslantern.com> Date: Sun, 28 Mar 2004 19:21:47 +0000 In-Reply-To: <9E7AF602-8085-11D8-AA68-000502631FBD@louisville.edu> Comments: In reply to Aaron Davies "Globbing for Empty Directories?" (Mar 28, 2:00am) References: <9E7AF602-8085-11D8-AA68-000502631FBD@louisville.edu> X-Mailer: Z-Mail (5.0.0 30July97) To: zsh-users@sunsite.dk Subject: Re: Globbing for Empty Directories? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: **** X-Spam-Status: No, hits=4.7 required=6.0 tests=RCVD_IN_DYNABLOCK, RCVD_IN_NJABL,RCVD_IN_NJABL_DIALUP,RCVD_IN_SORBS autolearn=no version=2.63 X-Spam-Hits: 4.7 On Mar 28, 2:00am, Aaron Davies wrote: } } Is there a way to get empty directories from a glob pattern? There's some discusson of this in the archives from a few months ago. It's not possible to tell if a directory is empty without actually looking for files in it. So the best you can do is something like this: isempty() { reply=( $REPLY/*(DN) ) (( $#reply )) && unset reply || reply=( $REPLY ) } print /path/to/emptydirectory(/e{isempty}) The (/) is important, otherwise you need to test [[ -d $REPLY ]] in the isempty function (because as-is it matches files as well as empty dirs). If you want to follow symlinks to empty directories you need: print /path/to/emptydirectory(-/e{isempty}) It's much easier to get only NON-empty directories: print /path/to/nonempty/*(DN[-1]:h) In this case, though, symlinks are always followed because of appending "/*" to the directory name, and there's not much to be done about it.