header line (@pxref{Subdirectories in Dired}), this command marks all
the files in that subdirectory.
+@item * N
+@kindex * N @r{(Dired)}
+@findex dired-number-of-marked-files
+Report what the number and size of the marked files are
+(@code{dired-number-of-marked-files}).
+
@item * *
@kindex * * @r{(Dired)}
@findex dired-mark-executables
(define-key map "*/" 'dired-mark-directories)
(define-key map "*@" 'dired-mark-symlinks)
(define-key map "*%" 'dired-mark-files-regexp)
+ (define-key map "*N" 'dired-number-of-marked-files)
(define-key map "*c" 'dired-change-marks)
(define-key map "*s" 'dired-mark-subdir-files)
(define-key map "*m" 'dired-mark)
(define-key map [menu-bar immediate revert-buffer]
'(menu-item "Refresh" revert-buffer
:help "Update contents of shown directories"))
+ (define-key map [menu-bar immediate dired-number-of-marked-files]
+ '(menu-item "#Marked Files" dired-number-of-marked-files
+ :help "Display the number and size of the marked files"))
(define-key map [menu-bar immediate dashes]
'("--"))
(and fn (string-match-p regexp fn))))
"matching file")))
+(defun dired-number-of-marked-files ()
+ "Display the number and total size of the marked files."
+ (interactive)
+ (let* ((files (dired-get-marked-files nil nil nil t))
+ (nmarked
+ (cond ((null (cdr files))
+ 0)
+ ((and (= (length files) 2)
+ (eq (car files) t))
+ 1)
+ (t
+ (length files))))
+ (size (cl-loop for file in files
+ when (stringp file)
+ sum (file-attribute-size (file-attributes file)))))
+ (if (zerop nmarked)
+ (message "No marked files"))
+ (message "%d marked file%s (%sB total size)"
+ nmarked
+ (if (= nmarked 1)
+ ""
+ "s")
+ (file-size-human-readable size))))
+
(defun dired-mark-files-containing-regexp (regexp &optional marker-char)
"Mark all files with contents containing REGEXP for use in later commands.
A prefix argument means to unmark them instead.