(use magic-pipes) (use args) (use ports) (use alist-lib) (define (examine-file filename recurse-filter) (let ((dirent (->dirent filename))) (pp dirent) (when (and (eq? (dirent-type dirent) 'directory) (without-ports (lambda () (recurse-filter dirent)))) (for-each (lambda (inner-filename) (examine-file (make-pathname filename inner-filename) recurse-filter)) (directory filename #t))))) (receive (options operands before-exprs after-exprs usage) (parse-mp-args (command-line-arguments) (list (args:make-option (r recurse-filter) (required: "PROCEDURE-EXPR") "Recuse into directories that return non-#f when the filter procedure is applied to them.") (args:make-option (R recurse) #:nonw "Recurse into all subdirectories")) "filenames..." "Read the attributes of the listed files (and, if recursion is enabled, the sub-files of them) and output Magic Pipes dirent sexprs.") (let* ((ec (make-eval-context before-exprs (if (assq 'recurse-filter options) (list (parse-code (alist-ref options 'recurse-filter (lambda () #f)))) '()) after-exprs)) (recurse-filter (cond ((assq 'recurse options) ; All recursion (lambda (dirent) #t)) ((assq 'recurse-filter options) ; Recurse on filter expr (eval-context-handler-closure ec 0)) (else (lambda (dirent) #f)))) ; No recursion (paths (if (null? operands) (directory "." #t) operands))) (for-each (lambda (filename) (examine-file filename recurse-filter)) paths) (without-input-port (eval-context-end-closure ec))))