Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Globbing for Empty Directories?
- X-seq: zsh-users 7277
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Globbing for Empty Directories?
- Date: Sun, 28 Mar 2004 19:21:47 +0000
- In-reply-to: <9E7AF602-8085-11D8-AA68-000502631FBD@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <9E7AF602-8085-11D8-AA68-000502631FBD@xxxxxxxxxxxxxx>
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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author