std.fs.path
directory?
added in 3.0
(directory? path)checks whether a file is a directory
(directory? “src”) => true
(directory? “project.clj”) => false
empty-directory?
added in 3.0
(empty-directory? path)checks if a directory is empty, returns true if both are true
(empty-directory? “.”) => false
executable?
added in 3.0
(executable? path)checks whether a file is executable
(executable? “project.clj”) => boolean?
(executable? “/usr/bin/whoami”) => true
exists?
added in 3.0
(exists? path)checks whether a file exists
(exists? “project.clj”) => true
(exists? “NON.EXISTENT”) => false
file
added in 3.0
(file path)returns the input as a file
(file “project.clj”) => java.io.File
file-name
added in 3.0
(file-name x)returns the last section of the path
(str (file-name “src/hara”)) => “hara”
file-suffix
added in 3.0
(file-suffix file)encodes the type of file as a keyword
(file-suffix “hello.clj”) => :clj
(file-suffix “hello.java”) => :java
file-system
added in 3.0
(file-system x)returns the filesystem governing the path
(file-system “.”) ;; #object[sun.nio.fs.MacOSXFileSystem 0x512a9870 “sun.nio.fs.MacOSXFileSystem@512a9870”] => java.nio.file.FileSystem
file?
added in 3.0
(file? path)checks whether a file is not a link or directory
(file? “project.clj”) => true
(file? “src”) => false
input-stream
added in 3.0
(input-stream path)(input-stream path opts)opens a file as an input-stream
(input-stream “project.clj”)
last-modified
added in 3.0
(last-modified path)returns the last modified time as a long
(last-modified “project.clj”) => integer?
link?
added in 3.0
(link? path)checks whether a file is a link
(link? “project.clj”) => false
(link? (api/create-symlink “project.lnk” “project.clj”)) => true (api/delete “project.lnk”)
normalise
added in 3.0
(normalise s)creates a string that takes notice of the user home
(normalise “.”) => (str common/cwd “/” “.”)
(normalise “~/hello/world.txt”) => (str common/home “/hello/world.txt”)
(normalise “/usr/home”) => “/usr/home”
nth-segment
added in 3.0
(nth-segment x i)returns the nth segment of a given path
(str (nth-segment “/usr/local/bin” 1)) => “local”
output-stream
added in 3.0
(output-stream path)(output-stream path opts)opens a file as an output-stream
(output-stream “project.clj”)
parent
added in 3.0
(parent x)returns the parent of the given path
(str (parent “/usr/local/bin”)) => “/usr/local”
path?
added in 3.0
(path? x)checks to see if the object is of type Path
(path? (path “/home”)) => true
permissions
added in 3.0
(permissions path)returns the permissions for a given file
(permissions “src”) => “rwxr-xr-x”
read-all-bytes
added in 3.0
(read-all-bytes path)opens a file and reads the contents as a byte array
(read-all-bytes “project.clj”)
read-all-lines
added in 3.0
(read-all-lines path)opens a file and reads the contents as an array of lines
(read-all-lines “project.clj”)
readable?
added in 3.0
(readable? path)checks whether a file is readable
(readable? “project.clj”) => true
relativize
added in 3.0
(relativize x other)returns one path relative to another
(str (relativize “test” “src/hara”)) => “../src/hara”
section
added in 3.0
(section s & more)path object without normalisation
(str (section “project.clj”)) => “project.clj”
(str (section “src” “hara/time.clj”)) => “src/hara/time.clj”
segment-count
added in 3.0
(segment-count x)returns the number of segments of a given path
(segment-count “/usr/local/bin”) => 3
subpath
added in 3.0
(subpath x start end)returns the subpath of a given path
(str (subpath “/usr/local/bin/hello” 1 3)) => “local/bin”
to-file
added in 3.0
(to-file path)creates a java.io.File object
(to-file (section “project.clj”)) => (all java.io.File #(-> % str (= “project.clj”)))
typestring
added in 3.0
(typestring path)returns the shorthand string for a given entry
(typestring “src”) => “d”
(typestring “project.clj”) => “-”
writable?
added in 3.0
(writable? path)checks whether a file is writable
(writable? “project.clj”) => true
write-all-bytes
added in 3.0
(write-all-bytes path bytes)(write-all-bytes path bytes opts)writes a byte-array to file
(write-all-bytes “hello.txt” (.getBytes “Hello World”))
write-into
added in 3.0
(write-into path stream)(write-into path stream opts)writes a stream to a path
(write-into “project.clj” (java.io.FileInputStream. “project.clj”) {:options #{:replace-existing}})