4

I have dired and dired+ setup for viewing directory listings and use it as my file-manager for moving / copying files. Currently dired lists '0' as the size for all the subdirectories in any directory.

I would like to have dired calculate and display folder sizes. I would like this to be bound to a keystroke/mouse-click since I don't want dired to do this on every folder in every buffer.

As of now, I have "open in explorer" (w32-shell-execute in windows and gnome-open in gnome) bound to "O" from which I use Alt+Enter to calculate the subdirectory size.

2 Answers 2

3

This Emacs wiki page suggests using the following snippet to calculate the size of selected files and directories:

 (defun dired-get-size ()
  (interactive)
  (let ((files (dired-get-marked-files)))
    (with-temp-buffer
      (apply 'call-process "/usr/bin/du" nil t nil "-sch" files)
      (message "Size of all marked files: %s"
               (progn 
                 (re-search-backward "\\(^[0-9.,]+[A-Za-z]+\\).*total$")
                  (match-string 1))))))

 (define-key dired-mode-map (kbd "?") 'dired-get-size)

If I understand you correctly, you'd like to update value the Dired buffer directly. I'm not familiar enough with Dired's internals, but I guess it's shouldn't that hard.

2
  • I am ok if updating the dired buffer is not possible. I read also in the emacs wiki (emacswiki.org/emacs/Sunrise_Commander - jump to very end of page) that it is difficult to do so. However, I'd like a solution that would work in Linux as well as Windows. In fact, I primarily dired in Windows to escape from explorer. Is there 'du' for windows ?
    – koushik
    Aug 16, 2012 at 18:48
  • I found out that I can get 'du' working in windows (cygwin or git - that works for me). Thanks for the solution ! It'd be nice if I can somehow get this info to persist in the dired buffer...
    – koushik
    Aug 16, 2012 at 19:02
3

If your Emacs version is >=24.4, then you can try the dired-du library. It's available from the ELPA repository.

Once you've installed this lib: If your current buffer is in Dired mode, then you can do:

C-x M-r

that toggles the `dired-du-mode' and displays the recursive size of the directories 'in place' in the Dired buffer. If you visit a new Dired buffer, then it will show recursive buffers as well, until you toggle off the mode.

Another tip:

C-x C-h

toggles the size format. There are 3 formats:

  1. Default one from `ls' command.

  2. Human readable format.

  3. Numeric format with thousands comma separator.

You can customize the option `dired-du-size-format' to make your size formar choice persistent.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .