[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Sorting directory-files on their extension
From: |
Pascal J. Bourguignon |
Subject: |
Re: Sorting directory-files on their extension |
Date: |
Wed, 07 Oct 2009 17:17:13 +0200 |
User-agent: |
Gnus/5.101 (Gnus v5.10.10) Emacs/22.2 (gnu/linux) |
Nordlöw <per.nordlow@gmail.com> writes:
> On Oct 7, 4:35 pm, Nordlöw <per.nord...@gmail.com> wrote:
>> Does Emacs contain any built-in features for sorting file-names (list
>> of strings) on their (file) extension?
>>
>> /NOrdlöw
>
> Is this a good candidate?:
>
> (defun compare-extensions (a b)
> (compare-strings
> (file-name-extension a) 0 (length (file-name-extension a))
> (file-name-extension b) 0 (length (file-name-extension b))))
> ;; Use: (sort '("a.c" "a.h" "b.c" "b.h") 'compare-extensions)
No, it doesn't work because compare-strings always return true, while
sort expects an order function that returns true only when a<b.
(string< (file-name-extension a) (file-name-extension b))
is what you'd want. If you want it case insignificant, you can use
(string< (upcase (file-name-extension a))
(upcase (file-name-extension b)))
--
__Pascal Bourguignon__