File tree Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Original file line number Diff line number Diff line change 1
- (defproject org.ajoberstar /ike.cljj " 0.3 .0"
1
+ (defproject org.ajoberstar /ike.cljj " 0.4 .0"
2
2
:description " Clojure to Java interop APIs"
3
3
:url " https://github.com/ajoberstar/ike.cljj"
4
4
:license {:name " Eclipse Public License"
Original file line number Diff line number Diff line change 4
4
(:refer-clojure :exclude [list])
5
5
(:require [ike.cljj.stream :as stream]
6
6
[ike.cljj.function :refer [defsam ]]
7
- [clojure.java.io :as io])
7
+ [clojure.java.io :as io]
8
+ [clojure.string :as str])
8
9
(:import (java.nio.file Path Paths Files CopyOption LinkOption OpenOption StandardOpenOption FileVisitOption SimpleFileVisitor FileVisitResult)
9
10
(java.nio.file.attribute FileAttribute)
10
11
(java.nio.charset Charset StandardCharsets)
64
65
(let [more-array (into-array String more)]
65
66
(Paths/get x more-array)))
66
67
68
+ (defn extension
69
+ " Gets the extension of the path, if any. Nil returned if there is no extension."
70
+ [path]
71
+ (let [name (-> path .getFileName str)
72
+ begin (str/last-index-of name " ." )]
73
+ (when (and begin (< 0 begin) (< begin (dec (count name))))
74
+ (subs name (inc begin)))))
75
+
67
76
(defn exists?
68
77
" Tests whether the path exists."
69
78
[path]
Original file line number Diff line number Diff line change 38
38
(deftest path-accepts-multiple-args
39
39
(is (instance? Path (file/path " /etc" " fstab" ))))
40
40
41
+ (deftest extension-test
42
+ (is (= " flac" (file/extension (file/path " /home" " person" " music.flac" ))))
43
+ (is (= " conf" (file/extension (file/path " .music.conf" ))))
44
+ (is (nil? (file/extension (file/path " /etc" " temp." ))))
45
+ (is (nil? (file/extension (file/path " /var" " log" " app" " things" )))))
46
+
41
47
(deftest make-dir-test
42
48
(let [path (.resolve (file/temp-dir " make-dir" ) " the-dir" )]
43
49
(is (not (file/exists? path)))
You can’t perform that action at this time.
0 commit comments