CreateTemp opens a new file whose name matches a pattern. A * in the pattern is replaced so the name does not collide. Close the file, then RemoveAll the directory that contains it.
CreateTemp
*
Close
RemoveAll
(let [[dir err] (os.MkdirTemp "" "glj-temp") [file ferr] (os.CreateTemp dir "note-*.txt")] (println (nil? err)) (println (nil? ferr)) (.Write file "temp") (.Close file) (println (path:filepath.Ext (.Name file))) (println (slurp (.Name file))) (os.RemoveAll dir))
The extension comes from the pattern. The directory name itself is random and is not printed.
$ glj temporary-files.glj true true .txt temp
Next example: Testing.
A hands-on tour in the style of Go by Example. Glojure is a Clojure interpreter hosted on Go.