(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
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 source target)(copy source target opts)copies all specified files from one to another
(copy "src" ".src" {:include [".clj"]}) => map?
(delete ".src")
copies all specified files from one to another
(copy "src" ".src" {:include [".clj"]})
=> map?
(delete ".src")(copy-into source target)(copy-into source target opts)copies a single file to a destination
(copy-into "src/hara/io/file" "dev/scratch/hara.io.file") => vector?
(delete "dev/scratch/hara.io.file")
copies a single file to a destination
(copy-into "src/hara/io/file"
"dev/scratch/hara.io.file")
=> vector?
(delete "dev/scratch/hara.io.file")(copy-single source target)(copy-single source target opts)copies a single file to a destination
(copy-single "project.clj" "dev/scratch/project.clj.bak" {:options #{:replace-existing}}) => (path "." "dev/scratch/project.clj.bak")
(delete "dev/scratch/project.clj.bak")
copies a single file to a destination
(copy-single "project.clj"
"dev/scratch/project.clj.bak"
{:options #{:replace-existing}})
=> (path "." "dev/scratch/project.clj.bak")
(delete "dev/scratch/project.clj.bak")(create-directory path)(create-directory path attrs)creates a directory on the filesystem
(do (create-directory "dev/scratch/.hello/.world/.foo") (directory? "dev/scratch/.hello/.world/.foo")) => true
(delete "dev/scratch/.hello")
creates a directory on the filesystem
(do (create-directory "dev/scratch/.hello/.world/.foo")
(directory? "dev/scratch/.hello/.world/.foo"))
=> true
(delete "dev/scratch/.hello")(create-symlink path link-to)(create-symlink path link-to attrs)creates a symlink to another file
(do (create-symlink "dev/scratch/project.lnk" "project.clj") (link? "dev/scratch/project.lnk")) => true
creates a symlink to another file
(do (create-symlink "dev/scratch/project.lnk" "project.clj")
(link? "dev/scratch/project.lnk"))
=> true
(create-tmpdir)(create-tmpdir prefix)creates a temp directory on the filesystem
(create-tmpdir) ;;=> #path:"/var/folders/d6/yrjldmsd4jd1h0nm970wmzl40000gn/T/4870108199331749225"
creates a temp directory on the filesystem (create-tmpdir) ;;=> #path:"/var/folders/d6/yrjldmsd4jd1h0nm970wmzl40000gn/T/4870108199331749225"
(create-tmpfile)creates a tempory file
(create-tmpfile) ;;#file:"/var/folders/rc/4nxjl26j50gffnkgm65ll8gr0000gp/T/tmp2270822955686495575" => java.io.File
creates a tempory file (create-tmpfile) ;;#file:"/var/folders/rc/4nxjl26j50gffnkgm65ll8gr0000gp/T/tmp2270822955686495575" => java.io.File
(delete root)(delete root opts)copies all specified files from one to another
(do (copy "src/hara/test.clj" ".src/hara/test.clj") (delete ".src" {:include ["test.clj"]})) => #{(str (path ".src/hara/test.clj"))}
(delete ".src") => set?
copies all specified files from one to another
(do (copy "src/hara/test.clj" ".src/hara/test.clj")
(delete ".src" {:include ["test.clj"]}))
=> #{(str (path ".src/hara/test.clj"))}
(delete ".src")
=> set?(directory? path)checks whether a file is a directory
(directory? "src") => true
(directory? "project.clj") => false
checks whether a file is a directory (directory? "src") => true (directory? "project.clj") => false
(empty-directory? path)checks if a directory is empty, returns true if both are true
(empty-directory? ".") => false
checks if a directory is empty, returns true if both are true (empty-directory? ".") => false
(executable? path)checks whether a file is executable
(executable? "project.clj") => false
(executable? "/usr/bin/whoami") => true
checks whether a file is executable (executable? "project.clj") => false (executable? "/usr/bin/whoami") => true
(exists? path)checks whether a file exists
(exists? "project.clj") => true
(exists? "NON.EXISTENT") => false
checks whether a file exists (exists? "project.clj") => true (exists? "NON.EXISTENT") => false
(file path)returns the input as a file
(file "project.clj") => java.io.File
returns the input as a file (file "project.clj") => java.io.File
(file->ns ns)converts a file string to an ns string
(file->ns "hara/io/file_test") => "hara.io.file-test"
converts a file string to an ns string (file->ns "hara/io/file_test") => "hara.io.file-test"
(file-name x)returns the last section of the path
(str (file-name "src/hara")) => "hara"
returns the last section of the path (str (file-name "src/hara")) => "hara"
(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
returns the filesystem governing the path (file-system ".") ;; #object[sun.nio.fs.MacOSXFileSystem 0x512a9870 "sun.nio.fs.MacOSXFileSystem@512a9870"] => java.nio.file.FileSystem
(file-type file)encodes the type of file as a keyword
(file-type "hello.clj") => :clj
(file-type "hello.java") => :java
encodes the type of file as a keyword (file-type "hello.clj") => :clj (file-type "hello.java") => :java
(file? path)checks whether a file is not a link or directory
(file? "project.clj") => true
(file? "src") => false
checks whether a file is not a link or directory (file? "project.clj") => true (file? "src") => false
(hidden? path)checks whether a file is hidden
(hidden? ".gitignore") => true
(hidden? "project.clj") => false
checks whether a file is hidden (hidden? ".gitignore") => true (hidden? "project.clj") => false
(input-stream path)(input-stream path opts)opens a file as an input-stream
(input-stream "project.clj")
opens a file as an input-stream (input-stream "project.clj")
(input-stream? x)checks if object is an input-stream
(input-stream? (input-stream "project.clj"))
checks if object is an input-stream (input-stream? (input-stream "project.clj"))
(link? path)checks whether a file is a link
(link? "project.clj") => false
(link? (create-symlink "project.lnk" "project.clj")) => true (delete "project.lnk")
checks whether a file is a link
(link? "project.clj")
=> false
(link? (create-symlink "project.lnk"
"project.clj"))
=> true
(delete "project.lnk")(list root)(list root opts)lists the files and attributes for a given directory
(list "src") => {"/Users/chris/Development/chit/hara/src" "rwxr-xr-x/d", "/Users/chris/Development/chit/hara/src/hara" "rwxr-xr-x/d"}
(list "../hara/src/hara/io" {:recursive true}) => {"/Users/chris/Development/chit/hara/src/hara/io" "rwxr-xr-x/d", "/Users/chris/Development/chit/hara/src/hara/io/file/reader.clj" "rw-r--r--/-", "/Users/chris/Development/chit/hara/src/hara/io/project.clj" "rw-r--r--/-", "/Users/chris/Development/chit/hara/src/hara/io/file/filter.clj" "rw-r--r--/-", ... ... "/Users/chris/Development/chit/hara/src/hara/io/file/path.clj" "rw-r--r--/-", "/Users/chris/Development/chit/hara/src/hara/io/file/walk.clj" "rw-r--r--/-", "/Users/chris/Development/chit/hara/src/hara/io/file.clj" "rw-r--r--/-"}
lists the files and attributes for a given directory
(list "src")
=> {"/Users/chris/Development/chit/hara/src" "rwxr-xr-x/d",
"/Users/chris/Development/chit/hara/src/hara" "rwxr-xr-x/d"}
(list "../hara/src/hara/io" {:recursive true})
=> {"/Users/chris/Development/chit/hara/src/hara/io" "rwxr-xr-x/d",
"/Users/chris/Development/chit/hara/src/hara/io/file/reader.clj" "rw-r--r--/-",
"/Users/chris/Development/chit/hara/src/hara/io/project.clj" "rw-r--r--/-",
"/Users/chris/Development/chit/hara/src/hara/io/file/filter.clj" "rw-r--r--/-",
... ...
"/Users/chris/Development/chit/hara/src/hara/io/file/path.clj" "rw-r--r--/-",
"/Users/chris/Development/chit/hara/src/hara/io/file/walk.clj" "rw-r--r--/-",
"/Users/chris/Development/chit/hara/src/hara/io/file.clj" "rw-r--r--/-"}(move source target)(move source target opts)moves a file or directory
(do (move "shortlist" ".shortlist") (move ".shortlist" "shortlist"))
(move ".non-existent" ".moved") => {}
moves a file or directory
(do (move "shortlist" ".shortlist")
(move ".shortlist" "shortlist"))
(move ".non-existent" ".moved")
=> {}(ns->file ns)converts an ns string to a file string
(ns->file 'hara.io.file-test) => "hara/io/file_test"
converts an ns string to a file string (ns->file 'hara.io.file-test) => "hara/io/file_test"
(nth-segment x i)returns the nth segment of a given path
(str (nth-segment "/usr/local/bin" 1)) => "local"
returns the nth segment of a given path (str (nth-segment "/usr/local/bin" 1)) => "local"
(option)(option k)shows all options for file operations
(option) => (contains [:atomic-move :create-new :skip-siblings :read :continue :create :terminate :copy-attributes :append :truncate-existing :sync :follow-links :delete-on-close :write :dsync :replace-existing :sparse :nofollow-links :skip-subtree])
(option :read) => java.nio.file.StandardOpenOption/READ
shows all options for file operations
(option)
=> (contains [:atomic-move :create-new
:skip-siblings :read :continue
:create :terminate :copy-attributes
:append :truncate-existing :sync
:follow-links :delete-on-close :write
:dsync :replace-existing :sparse
:nofollow-links :skip-subtree])
(option :read)
=> java.nio.file.StandardOpenOption/READ(output-stream path)(output-stream path opts)opens a file as an output-stream
(output-stream "project.clj")
opens a file as an output-stream (output-stream "project.clj")
(output-stream? x)checks if object is an output-stream
(output-stream? (output-stream "project.clj"))
checks if object is an output-stream (output-stream? (output-stream "project.clj"))
(parent path)returns the parent of the path
(str (parent "/hello/world.html")) => "/hello"
returns the parent of the path (str (parent "/hello/world.html")) => "/hello"
(path x)(path s & more)creates a `java.nio.file.Path object
(path "project.clj") ;;=> #path:"/Users/chris/Development/chit/hara/project.clj"
(path (path "project.clj")) ;; idempotent ;;=> #path:"/Users/chris/Development/chit/hara/project.clj"
(path "~") ;; tilda ;;=> #path:"/Users/chris"
(path "src" "hara/time.clj") ;; multiple arguments ;;=> #path:"/Users/chris/Development/chit/hara/src/hara/time.clj"
(path ["src" "hara" "time.clj"]) ;; vector ;;=> #path:"/Users/chris/Development/chit/hara/src/hara/time.clj"
(path (java.io.File. ;; java.io.File object "src/hara/time.clj")) ;;=> #path:"/Users/chris/Development/chit/hara/src/hara/time.clj"
(path (java.net.URI. ;; java.net.URI object "file:///Users/chris/Development/chit/hara/project.clj")) ;;=> #path:"/Users/chris/Development/chit/hara/project.clj"
creates a `java.nio.file.Path object
(path "project.clj")
;;=> #path:"/Users/chris/Development/chit/hara/project.clj"
(path (path "project.clj")) ;; idempotent
;;=> #path:"/Users/chris/Development/chit/hara/project.clj"
(path "~") ;; tilda
;;=> #path:"/Users/chris"
(path "src" "hara/time.clj") ;; multiple arguments
;;=> #path:"/Users/chris/Development/chit/hara/src/hara/time.clj"
(path ["src" "hara" "time.clj"]) ;; vector
;;=> #path:"/Users/chris/Development/chit/hara/src/hara/time.clj"
(path (java.io.File. ;; java.io.File object
"src/hara/time.clj"))
;;=> #path:"/Users/chris/Development/chit/hara/src/hara/time.clj"
(path (java.net.URI. ;; java.net.URI object
"file:///Users/chris/Development/chit/hara/project.clj"))
;;=> #path:"/Users/chris/Development/chit/hara/project.clj"
(path? x)checks to see if the object is of type Path
(path? (path "/home")) => true
checks to see if the object is of type Path (path? (path "/home")) => true
(permissions path)returns the permissions for a given file
(permissions "src") => "rwxr-xr-x"
returns the permissions for a given file (permissions "src") => "rwxr-xr-x"
(read-all-bytes path)opens a file and reads the contents as a byte array
(read-all-bytes "project.clj")
opens a file and reads the contents as a byte array (read-all-bytes "project.clj")
(read-all-lines path)opens a file and reads the contents as an array of lines
(read-all-lines "project.clj")
opens a file and reads the contents as an array of lines (read-all-lines "project.clj")
(read-code path)takes a file and returns a lazy seq of top-level forms
(->> (read-code "src/hara/io/file.clj") first (take 2)) => '(ns hara.io.file)
takes a file and returns a lazy seq of top-level forms
(->> (read-code "src/hara/io/file.clj")
first
(take 2))
=> '(ns hara.io.file)(readable? path)checks whether a file is readable
(readable? "project.clj") => true
checks whether a file is readable (readable? "project.clj") => true
(relativize path1 path2)returns the relationship between two paths
(str (relativize "hello" "hello/world.html")) => "world.html"
returns the relationship between two paths
(str (relativize "hello"
"hello/world.html"))
=> "world.html"(resource n)(resource n loader)accesses a url on the classpath
(resource "project.clj") => java.net.URL
accesses a url on the classpath (resource "project.clj") => java.net.URL
(root x)returns the root path
(str (root "/usr/local/bin")) => "/"
returns the root path (str (root "/usr/local/bin")) => "/"
(section s & more)path object without normalisation
(str (section "project.clj")) => "project.clj"
(str (section "src" "hara/time.clj")) => "src/hara/time.clj"
path object without normalisation (str (section "project.clj")) => "project.clj" (str (section "src" "hara/time.clj")) => "src/hara/time.clj"
(segment-count x)returns the number of segments of a given path
(segment-count "/usr/local/bin") => 3
returns the number of segments of a given path (segment-count "/usr/local/bin") => 3
(select root)(select root opts)selects all the files in a directory
(->> (select "src/hara/io/file") (map #(relativize "src/hara" %)) (map str) (sort)) => ["io/file" "io/file/attribute.clj" "io/file/charset.clj" "io/file/common.clj" "io/file/filter.clj" "io/file/option.clj" "io/file/path.clj" "io/file/reader.clj" "io/file/walk.clj" "io/file/watch.clj" "io/file/writer.clj"]
selects all the files in a directory
(->> (select "src/hara/io/file")
(map #(relativize "src/hara" %))
(map str)
(sort))
=> ["io/file"
"io/file/attribute.clj"
"io/file/charset.clj"
"io/file/common.clj"
"io/file/filter.clj"
"io/file/option.clj"
"io/file/path.clj"
"io/file/reader.clj"
"io/file/walk.clj"
"io/file/watch.clj"
"io/file/writer.clj"](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"
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"
(shorthand path)returns the shorthand string for a given entry
(shorthand "src") => "d"
(shorthand "project.clj") => "-"
returns the shorthand string for a given entry (shorthand "src") => "d" (shorthand "project.clj") => "-"
(subpath x start end)returns the subpath of a given path
(str (subpath "/usr/local/bin/hello" 1 3)) => "local/bin"
returns the subpath of a given path (str (subpath "/usr/local/bin/hello" 1 3)) => "local/bin"
(writable? path)checks whether a file is writable
(writable? "project.clj") => true
checks whether a file is writable (writable? "project.clj") => true
(write stream path)(write stream path opts)writes a stream to a path
(-> (java.io.FileInputStream. "project.clj") (write "project.clj" {:options #{:replace-existing}}))
writes a stream to a path
(-> (java.io.FileInputStream. "project.clj")
(write "project.clj"
{:options #{:replace-existing}}))(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"))
writes a byte-array to file (write-all-bytes "hello.txt" (.getBytes "Hello World"))
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |