std.fs
attributes
added in 3.0
(attributes path)shows all attributes for a given path
(attributes “project.clj”) ;; {:owner “chris”, ;; :group “staff”, ;; :permissions “rw-r–r–”, ;; :file-key “(dev=1000004,ino=2351455)”, ;; :ino 2351455, ;; :is-regular-file true. ;; :is-directory false, :uid 501, ;; :is-other false, :mode 33188, :size 4342, ;; :gid 20, :ctime 1476755481000, ;; :nlink 1, ;; :last-access-time 1476755481000, ;; :is-symbolic-link false, ;; :last-modified-time 1476755481000, ;; :creation-time 1472282953000, ;; :dev 16777220, :rdev 0} => map
copy
added in 3.0
(copy source target)(copy source target opts)copies all specified files from one to another
(copy “src” “.src” {:include “.clj”}) => map?
(delete “.src”)
copy-into
added in 3.0
(copy-into source target)(copy-into source target opts)copies a single file to a destination
(copy-into “src/std/fs.clj” “test-scratch/std.fs”) => vector?
(delete “test-scratch/std.fs”)
copy-single
added in 3.0
(copy-single source target)(copy-single source target opts)copies a single file to a destination
(copy-single “project.clj” “test-scratch/project.clj.bak” {:options #{:replace-existing}}) => (path/path “.” “test-scratch/project.clj.bak”)
(delete “test-scratch/project.clj.bak”)
create-directory
added in 3.0
(create-directory path)(create-directory path attrs)creates a directory on the filesystem
(do (create-directory “test-scratch/.hello/.world/.foo”) (path/directory? “test-scratch/.hello/.world/.foo”)) => true
(delete “test-scratch/.hello”)
create-symlink
added in 3.0
(create-symlink path link-to)(create-symlink path link-to attrs)creates a symlink to another file
(do (create-symlink “test-scratch/project.lnk” “project.clj”) (path/link? “test-scratch/project.lnk”)) => true
create-tmpdir
added in 3.0
(create-tmpdir)(create-tmpdir prefix)creates a temp directory on the filesystem
(create-tmpdir) ;;=> #path:“/var/folders/d6/yrjldmsd4jd1h0nm970wmzl40000gn/T/4870108199331749225”
create-tmpfile
added in 3.0
(create-tmpfile)(create-tmpfile contents)creates a tempory file
(create-tmpfile) ;;#file:“/var/folders/rc/4nxjl26j50gffnkgm65ll8gr0000gp/T/tmp2270822955686495575” => java.io.File
delete
added in 3.0
(delete root)(delete root opts)copies all specified files from one to another
(do (copy “src/std/fs.clj” “.src/std/fs.clj”) (delete “.src” {:include “fs.clj”})) => #{(str (path/path “.src/std/fs.clj”))}
(delete “.src”) => set?
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->ns
added in 3.0
(file->ns file)converts a file string to an ns string
(file->ns “std/fs_test”) => “std.fs-test”
file-name
added in 3.0
(file-name x)returns the last section of the path
(str (file-name “src/hara”)) => “hara”
file-namespace
added in 3.0
(file-namespace path)reads the namespace of the given path
(file-namespace “src/std/fs.clj”) => ’std.fs
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”)
list
added in 3.0
(list root)(list root opts)lists the files and attributes for a given directory
(list “src”)
(list “../hara/src/std/fs” {:recursive true})
move
added in 3.0
(move source target)(move source target opts)moves a file or directory
(do (move “shortlist” “.shortlist”) (move “.shortlist” “shortlist”))
(move “.non-existent” “.moved”) => {}
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”
ns->file
added in 3.0
(ns->file ns)converts an ns string to a file string
(ns->file ’std.fs-test) => “std/fs_test”
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”
option
added in 3.0
(option)(option k)shows all options for file operations
(option :read) => java.nio.file.StandardOpenOption/READ
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”)
read-code
added in 3.0
(read-code path)(read-code path f)takes a file and returns a lazy seq of top-level forms
(->> (read-code “src/std/fs.clj”) first (take 2)) => ’(ns std.fs)
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
select
added in 3.0
(select root)(select root opts)selects all the files in a directory
(->> (select “src/std/fs”) (map #(path/relativize “std/fs” %)) (map str) (sort))
set-attributes
added in 3.0
(set-attributes path m)sets all attributes for a given path
(set-attributes “project.clj” {:owner “chris”, :group “staff”, :permissions “rw-rw-rw-”}) ;;=> #path:“/Users/chris/Development/chit/lucidity/project.clj”
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}})