philipbohun.com

Glojure by Example: File Paths

path/filepath manipulates paths for the host operating system. On this machine the separator is /. Join cleans separators. Base, Dir, and Ext split a path. IsAbs reports whether it starts at the root.

(println (path:filepath.Join "dir" "sub" "file.txt"))
(println (path:filepath.Base "/tmp/a/file.txt"))
(println (path:filepath.Dir "/tmp/a/file.txt"))
(println (path:filepath.Ext "/tmp/a/file.txt"))
(println (path:filepath.IsAbs "/tmp/a"))
(println (path:filepath.IsAbs "a/b"))

Ext includes the dot.

$ glj file-paths.glj
dir/sub/file.txt
file.txt
/tmp/a
.txt
true
false

Next example: Directories.