From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@sunsite.dk
Subject: Re: Globbing for Empty Directories?
Date: Sun, 28 Mar 2004 19:21:47 +0000 [thread overview]
Message-ID: <1040328192147.ZM26160@candle.brasslantern.com> (raw)
In-Reply-To: <9E7AF602-8085-11D8-AA68-000502631FBD@louisville.edu>
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.
next prev parent reply other threads:[~2004-03-28 19:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-03-28 7:00 Aaron Davies
2004-03-28 19:21 ` Bart Schaefer [this message]
2004-03-28 20:13 ` Aaron Davies
2004-03-28 20:55 ` Bart Schaefer
2004-03-28 23:55 ` Aaron Davies
2004-03-29 0:54 ` Bart Schaefer
2004-03-29 6:05 ` Aaron Davies
2004-03-28 19:49 ` DervishD
2004-03-29 6:03 ` Aaron Davies
2004-03-29 13:28 ` DervishD
2004-03-29 15:19 ` Danek Duvall
2004-03-29 15:57 ` DervishD
2004-03-29 23:11 ` Aaron Davies
2004-03-29 23:24 ` DervishD
2004-03-31 1:44 ` Aaron Davies
2004-03-31 8:44 ` DervishD
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1040328192147.ZM26160@candle.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
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 NNTP newsgroup(s).