Liking cljdoc? Tell your friends :D

hara.io.file


attributesclj

(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
raw docstring

copyclj

(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")
raw docstring

copy-intoclj

(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")
raw docstring

copy-singleclj

(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")
raw docstring

create-directoryclj

(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")
raw docstring

(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

raw docstring

create-tmpdirclj

(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"
raw docstring

create-tmpfileclj

(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
raw docstring

deleteclj

(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?
raw docstring

directory?clj

(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
raw docstring

empty-directory?clj

(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
raw docstring

executable?clj

(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
raw docstring

exists?clj

(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
raw docstring

fileclj

(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
raw docstring

file->nsclj

(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"
raw docstring

file-nameclj

(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"
raw docstring

file-systemclj

(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
raw docstring

file-typeclj

(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
raw docstring

file?clj

(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
raw docstring

hidden?clj

(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
raw docstring

input-streamclj

(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")
raw docstring

input-stream?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"))
raw docstring

link?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")
raw docstring

listclj

(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--/-"}
raw docstring

moveclj

(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")
=> {}
raw docstring

ns->fileclj

(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"
raw docstring

nth-segmentclj

(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"
raw docstring

optionclj

(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
raw docstring

output-streamclj

(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")
raw docstring

output-stream?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"))
raw docstring

parentclj

(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"
raw docstring

pathclj

(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"
raw docstring

path?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
raw docstring

permissionsclj

(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"
raw docstring

read-all-bytesclj

(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")
raw docstring

read-all-linesclj

(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")
raw docstring

read-codeclj

(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)
raw docstring

readable?clj

(readable? path)

checks whether a file is readable

(readable? "project.clj") => true

checks whether a file is readable

(readable? "project.clj")
=> true
raw docstring

relativizeclj

(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"
raw docstring

resourceclj

(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
raw docstring

rootclj

(root x)

returns the root path

(str (root "/usr/local/bin")) => "/"

returns the root path

(str (root "/usr/local/bin"))
=> "/"
raw docstring

sectionclj

(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"
raw docstring

segment-countclj

(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
raw docstring

selectclj

(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"]
raw docstring

set-attributesclj

(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"
raw docstring

shorthandclj

(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")
=> "-"
raw docstring

subpathclj

(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"
raw docstring

writable?clj

(writable? path)

checks whether a file is writable

(writable? "project.clj") => true

checks whether a file is writable

(writable? "project.clj")
=> true
raw docstring

writeclj

(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}}))
raw docstring

write-all-bytesclj

(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"))
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close