Question

I have recently started to use dired in earnest, having belatedly checked out the advice to use C-x C-j given in one of the answers to this question. The 'jump' function is as useful as promised and has led me to investigate dired seriously. One snag is that I cannot group directories above files in dired buffers. I have tried putting the following in my .emacs.d file but it has no effect, presumably because I am running on Windows.

(setq dired-listing-switches "--group-directories-first -alh")

How can I achieve grouped directories above files in dired buffers in Windows 7?

[EDIT] as per the answer below, dired-sort-menu does seem to work - see following screenshot.

dired-sort-menu screenshot

Was it helpful?

Solution 2

DiredSortMenu may help you with that. It has an option for sorting with directories first.

If you dont't use a package like that, you may find the "ls" options supported in Windows by doing C-h f RET insert-directory (as you guessed, "--group-directories-first" is not supported).

OTHER TIPS

There is actually an option for this if you're using the ls emulation, as on Windows:

(setq ls-lisp-dirs-first t)

See (customize-group 'ls-lisp) for all the options. There are some useful ones -

; hide the link count, user, and group columns - default is '(links uid gid)
(setq ls-lisp-verbosity nil)

; use ISO dates (the first is for recent dates, second for old dates)
(setq ls-lisp-format-time-list '("%Y-%m-%d %H:%M" "%Y-%m-%d %H:%M"))
(setq ls-lisp-use-localized-time-format t)

Giving you a listing like this -

total used in directory 27734 available 171804716
dr-xr-xr-x       40960 2015-02-12 00:47 .
drwxrwxrwx       16384 2015-02-11 17:37 ..
dr-xr-xr-x       32768 2015-02-07 09:41 bookshelf
drwxrwxrwx       12288 2014-12-03 00:06 library
drwxrwxrwx        8192 2014-08-17 08:21 office
dr-xr-xr-x       16384 2015-02-10 19:54 projects
-rw-rw-rw-       14073 2015-01-31 17:25 android.org
-rw-rw-rw-       65736 2015-02-05 17:09 archive.org

dired can either use ls to get the list of files, or use some internal Elisp code instead. By default under Windows it does not use ls (in other systems, by default it uses ls). The --group-directories-first option is not supported by the Elisp code, so if you want to use it, you need to set ls-lisp-use-insert-directory-program to nil so as to tell dired to use ls (and of course, that will only work if/when you have a proper ls.exe installed which does support --group-directories-first.

Yes, DiredSortMenu is your friend. And dired-sort-menu+.el adds a few tweaks. Also, this EmacsWiki page has a bit more about sorting directories first, FWIW.

In Emacs 25.3.1, directories get sorted by setting:

(setq dired-listing-switches "-al --group-directories-first")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top