Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Filtering an array of file names



Thank you, Bart! This works perfectly.


On Thu, Sep 29, 2016 at 9:18 AM, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
wrote:

> 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