File system utilities in clojure.
File system utilities in clojure.
Current working directory. This cannot be changed in the JVM. Changing this will only change the working directory for functions in this library.
Current working directory. This cannot be changed in the JVM. Changing this will only change the working directory for functions in this library.
(->copy-options)
(->copy-options {:keys [replace-existing atomic-move copy-attributes
nofollow-links]})
Converts a hash-map of options into an array of CopyOption objects.
| key | description |
| -------------------|-------------|
| :replace-existing
| Adds StandardCopyOption/REPLACE_EXISTING to the array. Default: false
| :atomic-move
| Adds StandardCopyOption/ATOMIC_MOVE to the array. Default: false
| :copy-attributes
| Adds StandardCopyOption/COPY_ATTRIBUTES to the array. Default: false
| :nofollow-links
| Adds LinkOption/NOFOLLOW_LINKS to the array. Default: false
Converts a hash-map of options into an array of CopyOption objects. | key | description | | -------------------|-------------| | `:replace-existing`| Adds StandardCopyOption/REPLACE_EXISTING to the array. Default: `false` | `:atomic-move` | Adds StandardCopyOption/ATOMIC_MOVE to the array. Default: `false` | `:copy-attributes` | Adds StandardCopyOption/COPY_ATTRIBUTES to the array. Default: `false` | `:nofollow-links` | Adds LinkOption/NOFOLLOW_LINKS to the array. Default: `false`
(->file-attributes)
(->file-attributes {:keys [posix-file-permissions]})
Converts a seq of file-attributes into an array of FileAttribute objects.
Converts a seq of file-attributes into an array of FileAttribute objects.
(->link-options)
(->link-options {:keys [nofollow-links]})
Converts a hash-map of options into an array of LinkOption objects.
| key | description |
| -----------------|-------------|
| :nofollow-links
| Adds LinkOption/NOFOLLOW_LINKS to the array. Default: false
Converts a hash-map of options into an array of LinkOption objects. | key | description | | -----------------|-------------| | `:nofollow-links`| Adds LinkOption/NOFOLLOW_LINKS to the array. Default: `false`
(base-name path)
(base-name path trim-ext)
Return the base name (final segment/file part) of a path
.
If optional trim-ext
is a string and the path
ends with that
string, it is trimmed.
If trim-ext
is true, any extension is trimmed.
Return the base name (final segment/file part) of a `path`. If optional `trim-ext` is a string and the `path` ends with that string, it is trimmed. If `trim-ext` is true, any extension is trimmed.
(chdir path)
set!s the value of *cwd*
to path
. Only works inside of
with-mutable-cwd
set!s the value of `*cwd*` to `path`. Only works inside of [[with-mutable-cwd]]
(child-of? p c)
Takes two paths and checks to see if the first path is a parent of the second.
Takes two paths and checks to see if the first path is a parent of the second.
(chmod mode path)
Change file permissions. Returns path.
mode
can be a permissions string in octal or symbolic format.
Symbolic: any combination of r
(readable) w
(writable) and
x
(executable). It should be prefixed with +
to set or -
to
unset. And optional prefix of u
causes the permissions to be set
for the owner only.
Octal: a string of three octal digits representing user, group, and
world permissions. The three bits of each digit signify read, write,
and execute permissions (in order of significance). Note that group
and world permissions must be equal.
Examples:
(chmod "+x" "/tmp/foo") ; Sets executable for everyone
(chmod "u-wx" "/tmp/foo") ; Unsets owner write and executable
Change file permissions. Returns path. `mode` can be a permissions string in octal or symbolic format. Symbolic: any combination of `r` (readable) `w` (writable) and `x` (executable). It should be prefixed with `+` to set or `-` to unset. And optional prefix of `u` causes the permissions to be set for the owner only. Octal: a string of three octal digits representing user, group, and world permissions. The three bits of each digit signify read, write, and execute permissions (in order of significance). Note that group and world permissions must be equal. Examples: ``` (chmod "+x" "/tmp/foo") ; Sets executable for everyone (chmod "u-wx" "/tmp/foo") ; Unsets owner write and executable ```
(copy+ src dest)
Copy src
to dest
, create directories if needed.
Copy `src` to `dest`, create directories if needed.
(copy-dir from to)
Copy a directory from from
to to
. If to
already exists, copy the directory
to a directory with the same name as from
within the to
directory.
Copy a directory from `from` to `to`. If `to` already exists, copy the directory to a directory with the same name as `from` within the `to` directory.
(copy-dir-into from to)
Copy directory into another directory if destination already exists.
Copy directory into another directory if destination already exists.
(copy-file! source dest)
Copy a file from source
-> dest
.
Copy a file from `source` -> `dest`.
(copy-files! source-dir dest-dir)
Copy all files in source-dir
to dest-dir
. Overwrites existing files if last modified timestamp is not the same as
that of the source file — see #11699 for more context.
Copy all files in `source-dir` to `dest-dir`. Overwrites existing files if last modified timestamp is not the same as that of the source file — see #11699 for more context.
(copy-recursively from to)
(copy-recursively from
to
{:keys [replace-existing copy-attributes nofollow-links]})
(create-dir-if-not-exists! path)
Self-explanatory. Create a directory with path
if it does not already exist.
Self-explanatory. Create a directory with `path` if it does not already exist.
(create-directories! path)
(create-directories! path {:keys [posix-file-permissions]})
Warning: Setting posix-file-permissions on create will not always result in the permissions you specify. This is a limitation of the implementation. To guarantee those permissions you should set the permissions as another step after creating the file.
Warning: Setting posix-file-permissions on create will not always result in the permissions you specify. This is a limitation of the implementation. To guarantee those permissions you should set the permissions as another step after creating the file.
(create-directory path)
(create-directory path {:keys [posix-file-permissions]})
Warning: Setting posix-file-permissions on create will not always result in the permissions you specify. This is a limitation of the implementation. To guarantee those permissions you should set the permissions as another step after creating the file.
Warning: Setting posix-file-permissions on create will not always result in the permissions you specify. This is a limitation of the implementation. To guarantee those permissions you should set the permissions as another step after creating the file.
(create-file path)
(create-file path {:keys [posix-file-permissions content]})
Warning: Setting posix-file-permissions on create will not always result in the permissions you specify. This is a limitation of the implementation. To guarantee those permissions you should set the permissions as another step after creating the file.
Warning: Setting posix-file-permissions on create will not always result in the permissions you specify. This is a limitation of the implementation. To guarantee those permissions you should set the permissions as another step after creating the file.
(create-symlink link-path target-path)
Not allowing posix-file-permissions for file attributes since it is not supported on MacOS or Linux for this operation.
Not allowing posix-file-permissions for file attributes since it is not supported on MacOS or Linux for this operation.
(create-temp-directory prefix)
(create-temp-directory prefix {:keys [posix-file-permissions]})
Warning: Setting posix-file-permissions on create will not always result in the permissions you specify. This is a limitation of the implementation. To guarantee those permissions you should set the permissions as another step after creating the file.
Warning: Setting posix-file-permissions on create will not always result in the permissions you specify. This is a limitation of the implementation. To guarantee those permissions you should set the permissions as another step after creating the file.
(create-temp-file prefix suffix)
(create-temp-file prefix suffix {:keys [posix-file-permissions content]})
Warning: Setting posix-file-permissions on create will not always result in the permissions you specify. This is a limitation of the implementation. To guarantee those permissions you should set the permissions as another step after creating the file.
Warning: Setting posix-file-permissions on create will not always result in the permissions you specify. This is a limitation of the implementation. To guarantee those permissions you should set the permissions as another step after creating the file.
(creation-time path)
(creation-time path {:keys [nofollow-links]})
Get the creation time of a file or directory.
Get the creation time of a file or directory.
(delete-recursively path)
(delete-recursively path {:keys [nofollow-links] :or {nofollow-links true}})
(do-with-open-path-to-resource resource f)
Impl for with-open-path-to-resource
.
Impl for `with-open-path-to-resource`.
(ephemeral-dir prefix)
(ephemeral-dir prefix suffix)
(ephemeral-dir prefix suffix tries)
Create an ephemeral directory (will be deleted on JVM exit). Returns nil if dir could not be created even after n tries (default 10).
Create an ephemeral directory (will be deleted on JVM exit). Returns nil if dir could not be created even after n tries (default 10).
(ephemeral-file prefix)
(ephemeral-file prefix suffix)
(ephemeral-file prefix suffix tries)
Create an ephemeral file (will be deleted on JVM exit). Returns nil if file could not be created even after n tries (default 10).
Create an ephemeral file (will be deleted on JVM exit). Returns nil if file could not be created even after n tries (default 10).
(exec & body)
Execute a shell command in the current directory
Execute a shell command in the current directory
(exists? path)
(exists? path {:keys [nofollow-links]})
Return true if path
exists.
Return true if `path` exists.
(exists?? path)
Does file at path
actually exist?
TODO: exists?? is different with exists? why?
Does file at `path` actually exist? TODO: exists?? is different with exists? why?
(expand-home path)
If path
begins with a tilde (~
), expand the tilde to the value
of the user.home
system property. If the path
begins with a
tilde immediately followed by some characters, they are assumed to
be a username. This is expanded to the path to that user's home
directory. This is (naively) assumed to be a directory with the same
name as the user relative to the parent of the current value of
user.home
.
If `path` begins with a tilde (`~`), expand the tilde to the value of the `user.home` system property. If the `path` begins with a tilde immediately followed by some characters, they are assumed to be a username. This is expanded to the path to that user's home directory. This is (naively) assumed to be a directory with the same name as the user relative to the parent of the current value of `user.home`.
(extension path)
Return the extension part of a file.
Return the extension part of a file.
(extract-dir-from-jar jar-dir from to)
Takes the string path of a jar, a dir name inside that jar and a destination dir, and copies the from dir to the to dir.
Takes the string path of a jar, a dir name inside that jar and a destination dir, and copies the from dir to the to dir.
(extract-env-from-archive archive-path path-component dest-dir)
Extract the entire contents of a file from a archive (such as a JAR).
Extract the entire contents of a file from a archive (such as a JAR).
(file path & paths)
If path
is a period, replaces it with cwd and creates a new File object
out of it and paths
. Or, if the resulting File object does not constitute
an absolute path, makes it absolutely by creating a new File object out of
the paths
and cwd.
If `path` is a period, replaces it with cwd and creates a new File object out of it and `paths`. Or, if the resulting File object does not constitute an absolute path, makes it absolutely by creating a new File object out of the `paths` and cwd.
(file-exists-in-archive? archive-path & path-components)
True is a file exists in an archive.
True is a file exists in an archive.
(files-seq path)
Get a sequence of all files in path
, presumably a directory or an archive of some sort (like a JAR).
Get a sequence of all files in `path`, presumably a directory or an archive of some sort (like a JAR).
(find-files path pattern)
Find files matching given pattern
.
Find files matching given `pattern`.
(find-files* path pred)
Find files in path
by pred
.
Find files in `path` by `pred`.
(format-color color x)
(format-color color format-string & args)
Like format
, but colorizes the output. color
should be a symbol or keyword like green
, red
, yellow
, blue
,
cyan
, magenta
, etc. See the entire list of avaliable
colors here.
(format-color :red "Fatal error: %s" error-message)
Like `format`, but colorizes the output. `color` should be a symbol or keyword like `green`, `red`, `yellow`, `blue`, `cyan`, `magenta`, etc. See the entire list of avaliable colors [here](https://github.com/ibdknox/colorize/blob/master/src/colorize/core.clj). (format-color :red "Fatal error: %s" error-message)
(get-attribute path attribute)
(get-attribute path attribute {:keys [nofollow-links]})
(get-path & path-components)
Get a Path
for a file or directory in the default (i.e., system) filesystem named by string path component(s).
(get-path "/Users/cam/tservice/tservice/plugins")
;; -> #object[sun.nio.fs.UnixPath 0x4d378139 "/Users/cam/tservice/tservice/plugins"]
Get a `Path` for a file or directory in the default (i.e., system) filesystem named by string path component(s). (get-path "/Users/cam/tservice/tservice/plugins") ;; -> #object[sun.nio.fs.UnixPath 0x4d378139 "/Users/cam/tservice/tservice/plugins"]
(get-posix-file-permissions path)
(get-posix-file-permissions path {:keys [nofollow-links format]})
Get the file permissions of a file or directory.
Get the file permissions of a file or directory.
(glob pattern)
(glob root pattern)
Returns files matching glob pattern.
Returns files matching glob pattern.
(home)
(home user)
With no arguments, returns the current value of the user.home
system
property. If a user
is passed, returns that user's home directory. It
is naively assumed to be a directory with the same name as the user
located relative to the parent of the current value of user.home
.
With no arguments, returns the current value of the `user.home` system property. If a `user` is passed, returns that user's home directory. It is naively assumed to be a directory with the same name as the `user` located relative to the parent of the current value of `user.home`.
(iterate-dir path)
Return a sequence [root dirs files]
, starting from path
in depth-first order
Return a sequence `[root dirs files]`, starting from `path` in depth-first order
(join-paths path & paths)
Joins one or more path segments into a single String path object.
Joins one or more path segments into a single String path object.
(last-access-time path)
(last-access-time path {:keys [nofollow-links]})
Get the last access time of a file or directory
Get the last access time of a file or directory
(last-modified-time path)
(last-modified-time path {:keys [nofollow-links]})
Get the last modified time of a file or directory.
Get the last modified time of a file or directory.
(list-dir path)
List files and directories under path
.
List files and directories under `path`.
(name path)
Return the name part of a file.
Return the name part of a file.
(normalized path)
Return normalized (canonical) file.
Return normalized (canonical) file.
(ns-path n)
Takes a namespace symbol and creates a path to it. Replaces hyphens with underscores. Assumes the path should be relative to cwd.
Takes a namespace symbol and creates a path to it. Replaces hyphens with underscores. Assumes the path should be relative to cwd.
(parents f)
Get all the parent directories of a path.
Get all the parent directories of a path.
(path-ns path)
Takes a path
to a Clojure file and constructs a namespace symbol
out of the path.
Takes a `path` to a Clojure file and constructs a namespace symbol out of the path.
(read-all-attributes path)
(read-all-attributes path {:keys [nofollow-links]})
(read-attributes path attributes)
(read-attributes path attributes {:keys [nofollow-links]})
(rename old-path new-path)
Rename old-path
to new-path
. Only works on files.
Rename `old-path` to `new-path`. Only works on files.
(safe-rename current-path new-name)
(safe-rename current-path new-name {:keys [replace-existing atomic-move]})
(set-attribute path attribute value)
(set-attribute path attribute value {:keys [nofollow-links]})
(set-creation-time path time)
(set-creation-time path time {:keys [nofollow-links]})
Set the creation time of a file or directory.
Set the creation time of a file or directory.
(set-last-access-time path time)
(set-last-access-time path time {:keys [nofollow-links]})
Set the last access time of a file or directory.
Set the last access time of a file or directory.
(set-last-modified-time path time)
(set-last-modified-time path time {:keys [nofollow-links]})
Set the last modified time of a file or directory.
Set the last modified time of a file or directory.
(set-posix-file-permissions path permissions)
(set-posix-file-permissions path permissions {:keys [nofollow-links]})
(slurp-file-from-archive archive-path & path-components)
Read the entire contents of a file from a archive (such as a JAR).
Read the entire contents of a file from a archive (such as a JAR).
(split-ext path)
Returns a vector of [name extension]
.
Returns a vector of `[name extension]`.
(temp-dir prefix)
(temp-dir prefix suffix)
(temp-dir prefix suffix tries)
Create a temporary directory. Returns nil if dir could not be created even after n tries (default 10).
Create a temporary directory. Returns nil if dir could not be created even after n tries (default 10).
(temp-file prefix)
(temp-file prefix suffix)
(temp-file prefix suffix tries)
Create a temporary file. Returns nil if file could not be created even after n tries (default 10).
Create a temporary file. Returns nil if file could not be created even after n tries (default 10).
(tmpdir)
The temporary file directory looked up via the java.io.tmpdir
system property. Does not create a temporary directory.
The temporary file directory looked up via the `java.io.tmpdir` system property. Does not create a temporary directory.
(touch path & [time])
Set file modification time (default to now). Returns path
.
Set file modification time (default to now). Returns `path`.
The root of a unix system is /
, nil
on Windows
The root of a unix system is `/`, `nil` on Windows
(varargs klass)
(varargs klass xs)
Make a properly-tagged Java interop varargs argument. This is basically the same as into-array
but properly tags
the result.
(u/varargs String)
(u/varargs String ["A" "B"])
Make a properly-tagged Java interop varargs argument. This is basically the same as `into-array` but properly tags the result. (u/varargs String) (u/varargs String ["A" "B"])
(walk func path)
Lazily walk depth-first over the directory structure starting at
path
calling func
with three arguments [root dirs files]
.
Returns a sequence of the results.
Lazily walk depth-first over the directory structure starting at `path` calling `func` with three arguments `[root dirs files]`. Returns a sequence of the results.
(with-cwd cwd & body)
Execute body
with a changed working directory.
Execute `body` with a changed working directory.
(with-mutable-cwd & body)
Execute the body
in a binding with *cwd*
bound to *cwd*
.
This allows you to change *cwd*
with set!
.
Execute the `body` in a binding with `*cwd*` bound to `*cwd*`. This allows you to change `*cwd*` with `set!`.
(with-open-path-to-resource [path-binding resource-filename-str] & body)
Execute body
with an Path to a resource file or directory (i.e. a file in the project resources/
directory, or
inside the uberjar), cleaning up when finished.
Throws a FileNotFoundException if the resource does not exist; be sure to check with io/resource
or similar before
calling this.
(with-open-path-to-resouce [path "modules"]
...)
Execute `body` with an Path to a resource file or directory (i.e. a file in the project `resources/` directory, or inside the uberjar), cleaning up when finished. Throws a FileNotFoundException if the resource does not exist; be sure to check with `io/resource` or similar before calling this. (with-open-path-to-resouce [path "modules"] ...)
(zip-files from-files to-filepath)
Make a zip file with the from-files.
Make a zip file with the from-files.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close