[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [h-e-w] Display list of types of files in a directory
From: |
rob . davenport |
Subject: |
Re: [h-e-w] Display list of types of files in a directory |
Date: |
Thu, 18 Mar 2004 12:25:49 -0500 |
Wow, that's fantastic! Thanks Tom.
I fiddled with it a little (and learned a bit about CL too!) and came up
with this version - a tiny modification to the output format: made the
number of asterisks proportional to the percentage and moved them to the
right side. (As I think that's more how pocketd displayed it now that
I think about it harder! :)
Thanks again!
Rob
------------------------------------------------------------------------
;; pocketd.el
;; by Tom Capey <address@hidden> 3/18/2004
;; Thanks Tom!
;; tiny format mods by Rob Davenport 3/18/2004
(require 'cl)
(defun pocket-d-display-directory (directory)
(interactive "DDirectory: ")
(let ((suffix-count '())
(total 0)
(max 0)
(target-column 50)
(buffer (get-buffer-create "*Pocket D Display*"))
(extension-description "Extension:"))
(set-buffer buffer)
(erase-buffer)
(loop for file in (remove-if-not #'file-regular-p
(directory-files directory t))
for suffix = (file-name-extension file)
for assoc-elt = (assoc suffix suffix-count)
count file into suffix-total
maximize (length suffix) into max-length
finally (setq total suffix-total
max (max (length extension-description)
max-length))
if assoc-elt
do (incf (cdr assoc-elt))
else
do (push (cons suffix 1) suffix-count))
(insert "Directory of " directory "\n\n"
extension-description "\n"
(make-string (length extension-description) ?=)
"\n\n"
"")
(if (zerop total) (insert "No files found")
(loop for elt in (sort* suffix-count #'string< :key #'car)
do (insert (format "%s" (car elt)))
(insert (make-string (1+ (- max (current-column))) ? ))
(insert (format " %6d (%5.2f%%)"
(cdr elt)
(* 100 (/ (cdr elt) (float total)))))
(insert (make-string
(car (round* (* (- target-column (current-column))
(/ (cdr elt) (float total))))) ?*))
(insert (format "\n"))
))
(switch-to-buffer-other-window buffer)))
-------------------------------------------------------------------------
(You might want to pretty it up as I reformatted it a tad so it
wouldn't wrap (I hope).)
--
Rob Davenport
ABB Inc., Automation Technology Products
email: address@hidden