Fork me on GitHub
#babashka
<
2024-02-11
>
teodorlu12:02:10

Hi! Is there a babashka/fs idiom to figure out “when was the last timestamp something was changed in this folder”?

1
teodorlu12:02:49

I started with this:

(->>
 (fs/glob "." "**/*.{js,html,clj,md,edn}")
 (map fs/last-modified-time)
 (take 3)
 )
;; => (#object[java.nio.file.attribute.FileTime 0x79af5549 "2024-01-12T21:23:01.321554243Z"]
;;     #object[java.nio.file.attribute.FileTime 0x19875a94 "2024-01-30T20:54:39.24684365Z"]
;;     #object[java.nio.file.attribute.FileTime 0x27b75483 "2024-02-11T11:55:36.44456266Z"])
But clojure.core/max doesn’t work with java.nio.file.attribute.FileTime.

borkdude12:02:00

you can convert it to miliseconds probably

borkdude12:02:01

and then use max

borkdude12:02:15

or maybe use sort

borkdude12:02:20

and take the first one

borkdude12:02:57

or use max-key + the function that converts to ms

teodorlu12:02:40

Awesome, thanks! I wrote these two:

(->>
 (fs/glob "." "**/*.{js,html,clj,md,edn}")
 (map fs/last-modified-time)
 (map fs/file-time->millis)
 (reduce max)
 fs/millis->file-time)
;; => #object[java.nio.file.attribute.FileTime 0x43aeb233 "2024-02-11T12:36:33.663Z"]


(apply max-key
       (comp fs/file-time->millis fs/last-modified-time)
       (fs/glob "." "**/*.{js,css,html,clj,md,edn}"))
;; => #object[sun.nio.fs.UnixPath 0xb1a81e "draft/mikrobloggeriet/teodor/last_changed.clj"]

👍 1
💡 1
teodorlu13:02:51

fs/glob is just awesome. :hugging_face:

❤️ 1
yes 2
jmglov07:02:13

I have to say, babashka.fs is one of my favourite namespaces of all time! 😍

2
❤️ 1