help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: customized name sorting in dired


From: Kevin Rodgers
Subject: Re: customized name sorting in dired
Date: Wed, 17 Nov 2004 11:51:54 -0700
User-agent: Mozilla Thunderbird 0.9 (X11/20041105)

Florian von Savigny wrote:
> thanks very much. I ashamedly admit I have only now hit on the idea of
> renaming the entries such that they should sort properly with standard
> routines: beginning with YYMMDD, instead of ending with DDMMYY. Hence,
> my current need for custom sorting is suddenly gone. However, I will
> supply the answer in case anybody is interested in the problem (I am
> of course interested, but the urge is gone).

That's what I wanted to suggest, but I figured the files were named that
way for a reason.  I prefer CCYY-MM-DD myself.

> So please, only bother with it if you find it plain interesting,
> anybody. Thanks for having been helpful, Kevin.

You're welcome!

> Kevin Rodgers <ihs_4664@yahoo.com> writes:
>
>>I'm not familiar with the ls -U option (a GNU extension?), but calling
>>dired like that works for me in Emacs 21.3 on Solaris.  Perhaps you
>>could post your code and the resulting error message.
>
>
> The manpage says "-U: do not sort; list entries in directory
> order". The reason why I tried this was because I first tried a shell
> version of what I was now trying to find for Emacs. I wrote a Perl
> script that takes the directory entries and returns them in the sort
> order I want, separated by spaces. Calling
>
>         ls -ld `sorting_script`
>
> (-d because the entries are directories) would then display the usual
> information but re-sort it - such as when you have three files a, b,
> and c, and say "ls b a c": ls will resort them to "a b c". Adding the
> -U switch has precluded this re-sorting on my system (maybe not the
> task it was originally intended for). So much for that.

Right.

> My idea how to implement this under Emacs was such: the documentation
> for dired says:
>
> (dired DIRNAME &optional SWITCHES)
> ...
> If DIRNAME is a cons, its first element is taken as the directory name
> and the rest as an explicit list of files to make directory entries
> for.
>
> I figured that to imitate the shell solution above, I had to supply
> the directory name as the car, and the sorted list of entries as the
> cons, which ls would dutyfully not re-sort if I supplied the -U
> switch:
>
>
> (defun dired-entries-in-my-order (dir)
>   "Run dired on DIR; display entries in proper order."
>   (interactive "DDirectory: ")
>   (dired (cons
>           dir
>      (sort (directory-files
>             dir
>             nil)
>            'by-date-in-name))  ;; see first posting
>     "lU"))

You need to pass SWITCHES as "-lU", because it is used as the value of
dired-listing-switches.

--
Kevin Rodgers


reply via email to

[Prev in Thread] Current Thread [Next in Thread]