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

[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: Tom Capey
Subject: Re: [h-e-w] Display list of types of files in a directory
Date: 18 Mar 2004 11:31:25 +0000
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

* rob.davenport <address@hidden> writes:

> Years ago I used to use a command-line utility on Windows called
> PocketD which would (with the correct parameters used) display
> a list of the types of files (based on extension) in a directory, and
> the number and percentage of each.

> For example,  a typical output might have looked like:

> Directory of d:\projects\code\test1
> Ext
> -----
> h       ****************** (34) 31%
> cpp     ************** (28)             21%
> obj     ************** (28)             21%
> sbr     ************** (28)             21%
> pdb        * (1)                          1%
> ....
> etc.

> That's not exact (and I doubt the numbers add up), but that's the
> general
> idea.
> There were other options to show size allocated to each type etc.


  here's a start:


(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 (make-string (- target-column (current-column)) ?*))
               (insert (format "  %2d (%.2f%%)\n"
                               (cdr elt)
                               (* 100 (/ (cdr elt) (float total)))))))
    (switch-to-buffer-other-window buffer)))



/Tom
-- 
"For example, because of the Kawesqar's nomadic past, they rarely use
the future tense; given the contingency of moving constantly by canoe,
it was all but unnecessary." -- NYT




---  Disclaimer  ---

Unless otherwise agreed expressly in writing by a Director of Edina Software, 
this communication is to be treated as confidential and the information in it 
may not be used or disclosed except for the purpose for which it has been sent. 
If you have reason to believe that you are not the intended recipient of this 
communication, please contact the sender immediately.




reply via email to

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