Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Filtering an array of file names
- X-seq: zsh-users 21986
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Filtering an array of file names
- Date: Thu, 29 Sep 2016 00:18:53 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=AjvY4HPcltQKT31CTFvZoryIja+uc+GevSjloWS3uFA=; b=UJzpIrgXBFs+/Bls6s3e5p1kCrhQQf7cD+rGgNUi3fuMUWjCu4uyyfqFf84RUWiCr2 3/Mdnjar9ndA5Hbe4wWijU5nF6IArvWzjooUhfCkk/ZfaB121iNiWv7Vbg4Dt4mJArMZ rgzYyJCxI5bRXeRYGU4qdPwGiWlIwkz2y4Re/C3OVXKV2P3WETAgEh022CTv3GC6b2tB GZcY51U4DcIEFctfau+TuycGxuX3uSXW/r2ZGni2k5P/4scsllCowke2934FTtUrXPId VuVaSBoUxFTxPguL3LkL6tp+lwNMysGscoPQO6txG11xoy5hh9Z/2C949cwSrRqabcCJ qmww==
- In-reply-to: <CABZhJg9vf0OZyXbSOcX_7sA7aN=cHtDQq08sLKy_0Vs6xkUR1g@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CABZhJg9vf0OZyXbSOcX_7sA7aN=cHtDQq08sLKy_0Vs6xkUR1g@mail.gmail.com>
On Sep 29, 8:43am, Jesper Nygards wrote:
}
} Suppose I have an array of file names, generated from some external
} program. Is there an zsh-idiomatic way of filtering this array to only
} keep directories?
Are these local file names that you can compare to the filesystem? If
so, you can use rc-expand-param and globbing qualifiers:
directories=( ${^allfiles}(/) )
(This didn't work on some old versions of the shell, where qualifiers
were interpreted only if the preceding word had a globbing character.)
If they don't refer to the local filesystem, you'll need the array to
have already marked them somehow, such as with a trailing slash, and
then ${(M)files:#*/} would work.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author