2018-04-23 17:14:40 +03:00
|
|
|
(defmodule Filepath
|
|
|
|
|
|
|
|
(use Array)
|
|
|
|
|
2019-02-15 16:48:49 +03:00
|
|
|
(doc dir-from-path "removes the file name part of a path to a file, similar to the `basename` utility in Shell scripting.")
|
2018-04-23 17:14:40 +03:00
|
|
|
(defn dir-from-path [path]
|
|
|
|
(let [segments (split-by path &[\/])
|
2018-05-20 10:57:51 +03:00
|
|
|
n (dec (length &segments))
|
2020-02-11 11:09:30 +03:00
|
|
|
without-last (prefix &segments n)]
|
2018-11-26 23:19:41 +03:00
|
|
|
(concat &(copy-map &(fn [s] (str* s "/")) &without-last))))
|
2018-04-23 17:14:40 +03:00
|
|
|
|
2019-02-15 16:48:49 +03:00
|
|
|
(doc file-from-path "removes the base name part of a path to a file, similar to the `filename` utility in Shell scripting.")
|
|
|
|
(defn file-from-path [path]
|
|
|
|
(let [segments (split-by path &[\/])]
|
|
|
|
; this is actually safe here, because split by will return an array of
|
|
|
|
; length > 0
|
2020-11-27 12:19:06 +03:00
|
|
|
@(unsafe-last &segments)))
|
2018-04-23 17:14:40 +03:00
|
|
|
)
|