From: Ralph Ronnquist Date: Mon, 8 May 2023 01:07:31 +0000 (+1000) Subject: initial X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=7032bd6739c4224f507e67a39037528d430efcbe;p=rrq%2Fnewlisp%2Fnewest.git initial --- 7032bd6739c4224f507e67a39037528d430efcbe diff --git a/.gitweb b/.gitweb new file mode 100644 index 0000000..e62c928 --- /dev/null +++ b/.gitweb @@ -0,0 +1,2 @@ +description = Find the newest file of each of the given directories. +category = newlisp diff --git a/newest.lsp b/newest.lsp new file mode 100755 index 0000000..3fe925f --- /dev/null +++ b/newest.lsp @@ -0,0 +1,32 @@ +#!/usr/bin/newlisp +# +# Find the newest file of each of the given directories + +;; Return pair (time file) for given file +(define (modtime F) + (if (null? F) '(0 F) (list? F) F (list (file-info F 6) F))) + +(define (files-in D) + (clean (fn (x) (or (= x ".") (= x ".."))) (directory D ""))) + +;; Return the list of full pathnames for all files in the given +;; directory, excluding "." and "..". +(define (dir-list D) + (if (= D ".") (files-in D) + (map (fn (F) (format "%s/%s" D F)) (files-in D)))) + +;; Return pair of (time file) +(define (newest FILES) + ;;(println (list 'newest FILES)) + (if (null? FILES) '() + (last + (sort + (map modtime + (map (fn (F) (if (directory? F) (newest (dir-list F)) F)) + FILES)))))) + +(define (report x) (format "%s %s" (date (x 0)) (x 1))) + +(map println (map report (sort (map newest (map list (2 (main-args))))))) +(exit 0) +