initial
[rrq/newlisp/newest.git] / newest.lsp
1 #!/usr/bin/newlisp
2 #
3 # Find the newest file of each of the given directories
4
5 ;; Return pair (time file) for given file
6 (define (modtime F)
7   (if (null? F) '(0 F) (list? F) F (list (file-info F 6) F)))
8
9 (define (files-in D)
10   (clean (fn (x) (or (= x ".") (= x ".."))) (directory D "")))
11
12 ;; Return the list of full pathnames for all files in the given
13 ;; directory, excluding "." and "..".
14 (define (dir-list D)
15   (if (= D ".") (files-in D)
16     (map (fn (F) (format "%s/%s" D F)) (files-in D))))
17
18 ;; Return pair of (time file)
19 (define (newest FILES)
20   ;;(println (list 'newest FILES))
21   (if (null? FILES) '()
22     (last
23      (sort
24       (map modtime
25            (map (fn (F) (if (directory? F) (newest (dir-list F)) F))
26                 FILES))))))
27
28 (define (report x) (format "%s %s" (date (x 0)) (x 1)))
29
30 (map println (map report (sort (map newest (map list (2 (main-args)))))))
31 (exit 0)
32