(require 'dired) (defvar nodots "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*") (defun dired-go-to-first () (interactive) (goto-char (point-min)) (dired-next-line 1) (skip-chars-forward " \n\t")) (defun dired-is-empty-p (directory-name) (null (directory-files directory-name nil nodots t 1))) (defun directory-number-files (directory-name &optional omit-filter) (length (directory-files directory-name nil omit-filter t))) (defun dired-mark-empty-dirs () (interactive) (when (equal major-mode 'dired-mode) (let ((curr-dir)) (save-excursion (dired-go-to-first) (while (not (eobp)) (setq curr-dir (dired-file-name-at-point)) (cond ((or (null curr-dir) (string= curr-dir ".") (string= curr-dir "..")) ;; do nothing here ) ((file-directory-p curr-dir) (when (dired-is-empty-p curr-dir) (dired-mark 1) (dired-previous-line 1)))) (dired-next-line 1)))))) (defun test-1 (dir-name count) "Ask for COUNT number of files from directory DIR-NAME." (let ((max (length (directory-files dir-name nil nil t))) (res (length (directory-files dir-name nil nil t count)))) (cond ((>= max count) (if (= res count) (message "passed: asked: %d get: %d number files in dir: %d" count res max) (message "not-passed: asked: %s get: %s number files in dir: %s" count res max))) ((< max count) (if (< res count) (message "passed: asked: %d get: %d number files in dir: %d" count res max) (message "not-passed: asked: %s get: %s number files in dir: %s" count res max))) (t (message "Invalid case!"))))) (defun test-2 (dir-name count) "Ask for random number of files in interval [1,COUNT] files from every subdir of directory DIR-NAME." (let ((dirs (directory-files dir-name t nodots t))) (dolist (curr-dir dirs) (when (file-directory-p curr-dir) (test-1 curr-dir (+ 1 (random count))))))) ;;(benchmark-run-compiled 10 (dired-is-empty-p "/some/path")) ;; must be in some dired buffer for this ;;(benchmark-run-compiled 10 (dired-mark-empty-dirs))