Liking cljdoc? Tell your friends :D

babashka.fs


absolute?clj

(absolute? f)

Returns true if f represents an absolute path via Path#isAbsolute.

Returns true if `f` represents an absolute path via [Path#isAbsolute](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Path.html#isAbsolute()).
sourceraw docstring

absolutizeclj

(absolutize f)

Converts f into an absolute Path via Path#toAbsolutePath.

Converts `f` into an absolute `Path` via [Path#toAbsolutePath](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Path.html#toAbsolutePath()).
sourceraw docstring

canonicalizeclj

(canonicalize f)
(canonicalize f {:keys [:nofollow-links]})

Returns the canonical Path for f via File#getCanonicalPath.

Options:

This function can be used as an alternative to real-path which requires files to exist.

Returns the canonical `Path` for `f` via [File#getCanonicalPath](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/File.html#getCanonicalPath()).

Options:
* [`:nofollow-links`](/README.md#nofollow-links), when set, falls back on [[absolutize]] + [[normalize]].

This function can be used as an alternative to [[real-path]] which requires files to exist.
sourceraw docstring

componentsclj

(components f)

Returns a seq of all components of f as paths. i.e.: split on the file-separator.

Returns a seq of all components of `f` as paths.
i.e.: split on the [[file-separator]].
sourceraw docstring

copyclj

(copy src dest)
(copy src dest {:keys [replace-existing copy-attributes nofollow-links]})

Copies src file to dest dir or file using Files/copy.

Options:

  • :replace-existing
  • :copy-attributes
  • :nofollow-links (used to determine to copy symbolic link itself or not). Returns dest as path.
Copies `src` file to `dest` dir or file using [Files/copy](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#copy(java.nio.file.Path,java.nio.file.Path,java.nio.file.CopyOption...)).

Options:
* `:replace-existing`
* `:copy-attributes`
* [`:nofollow-links`](/README.md#nofollow-links) (used to determine to copy symbolic link itself or not).
Returns `dest` as path.
sourceraw docstring

copy-treeclj

(copy-tree src dest)
(copy-tree src
           dest
           {:keys [:replace-existing :copy-attributes :nofollow-links]
            :as opts})

Copies entire file tree from src to dest. Creates dest if needed using create-dirs, passing it the :posix-file-permissions option. Supports same options as copy. Returns dest as Path

Copies entire file tree from `src` to `dest`. Creates `dest` if needed
using [[create-dirs]], passing it the `:posix-file-permissions`
option. Supports same options as [[copy]].
Returns `dest` as `Path`
sourceraw docstring

create-dirclj

(create-dir path)
(create-dir path {:keys [:posix-file-permissions]})

Creates dir using Files/createDirectory. Does not create parents.

Options:

  • :posix-file-permissions permission for unix-like systems
Creates dir using [Files/createDirectory](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#createDirectory(java.nio.file.Path,java.nio.file.attribute.FileAttribute...)).
Does not create parents.

Options:
* `:posix-file-permissions` permission for unix-like systems
sourceraw docstring

create-dirsclj

(create-dirs path)
(create-dirs path {:keys [:posix-file-permissions]})

Creates directories for path using Files/createDirectories. Also creates parents if needed. Doesn't throw an exception if the dirs exist already. Similar to mkdir -p

Options:

  • :posix-file-permissions permission for unix-like systems
Creates directories for `path` using [Files/createDirectories](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#createDirectories(java.nio.file.Path,java.nio.file.attribute.FileAttribute...)).
Also creates parents if needed.
Doesn't throw an exception if the dirs exist already. Similar to `mkdir -p`

Options:
* `:posix-file-permissions` permission for unix-like systems
sourceraw docstring

create-fileclj

(create-file path)
(create-file path {:keys [:posix-file-permissions]})

Creates empty file at path using Files/createFile.

Options:

  • :posix-file-permissions string format for posix file permissions is described in the str->posix docstring.
Creates empty file at `path` using [Files/createFile](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#createFile(java.nio.file.Path,java.nio.file.attribute.FileAttribute...)).

Options:
* `:posix-file-permissions` string format for posix file permissions is described in the [[str->posix]] docstring.
sourceraw docstring

(create-link link existing)

Create a new link (directory entry) for an existing file via Files/createLink.

Create a new `link` (directory entry) for an `existing` file via [Files/createLink](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#createLink(java.nio.file.Path,java.nio.file.Path)).
sourceraw docstring

(create-sym-link link target)

Create a symbolic link to target via Files/createSymbolicLink.

As of this writing, JDKs do not recognize empty-string target "" as the cwd. Consider instead using a target of "." to link to the cwd.

Create a symbolic `link` to `target` via [Files/createSymbolicLink](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#createSymbolicLink(java.nio.file.Path,java.nio.file.Path,java.nio.file.attribute.FileAttribute...)).

As of this writing, JDKs do not recognize empty-string `target` `""` as the cwd.
Consider instead using a `target` of `"."` to link to the cwd.
sourceraw docstring

create-temp-dirclj

(create-temp-dir)
(create-temp-dir {:keys [:dir :prefix :posix-file-permissions] :as opts})

Creates a directory using Files/createTempDirectory.

This function does not set up any automatic deletion of the directories it creates. See with-temp-dir for that functionality.

Options:

  • :dir: Directory in which to create the new directory. Defaults to default system temp dir (e.g. /tmp); see temp-dir. Must already exist.
  • :prefix: Provided as a hint to the process that generates the name of the new directory. In most cases, this will be the beginning of the new directory name. Defaults to a random (v4) UUID.
  • :posix-file-permissions: The new directory will be created with these permissions, given as a String as described in str->posix. If not specified, uses the file system default permissions for new directories.
  • :warning: :path [DEPRECATED] Previous name for :dir, kept for backwards compatibility. If both :path and :dir are given (don't do that!), :dir is used.

Examples:

  • (create-temp-dir)
  • (create-temp-dir {:posix-file-permissions "rwx------"})
  • (create-temp-dir {:dir (path (cwd) "_workdir") :prefix "process-1-"})
Creates a directory using [Files/createTempDirectory](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#createTempDirectory(java.nio.file.Path,java.lang.String,java.nio.file.attribute.FileAttribute...)).

This function does not set up any automatic deletion of the directories it
creates. See [[with-temp-dir]] for that functionality.

Options:
* `:dir`: Directory in which to create the new directory. Defaults to default
system temp dir (e.g. `/tmp`); see [[temp-dir]]. Must already exist.
* `:prefix`: Provided as a hint to the process that generates the name of the
new directory. In most cases, this will be the beginning of the new directory
name. Defaults to a random (v4) UUID.
* `:posix-file-permissions`: The new directory will be created with these
permissions, given as a String as described in [[str->posix]]. If not
specified, uses the file system default permissions for new directories.
* :warning: `:path` **[DEPRECATED]** Previous name for `:dir`, kept
for backwards compatibility. If both `:path` and `:dir` are given (don't do
that!), `:dir` is used.

Examples:
* `(create-temp-dir)`
* `(create-temp-dir {:posix-file-permissions "rwx------"})`
* `(create-temp-dir {:dir (path (cwd) "_workdir") :prefix "process-1-"})`
sourceraw docstring

create-temp-fileclj

(create-temp-file)
(create-temp-file {:keys [:dir :prefix :suffix :posix-file-permissions]
                   :as opts})

Creates an empty file using Files/createTempFile.

This function does not set up any automatic deletion of the files it creates. Create the file in a with-temp-dir for that functionality.

Options:

  • :dir: Directory in which to create the new file. Defaults to default system temp dir (e.g. /tmp); see temp-dir. Must already exist.
  • :prefix: Provided as a hint to the process that generates the name of the new file. In most cases, this will be the beginning of the new file name. Defaults to a random (v4) UUID.
  • :suffix: Provided as a hint to the process that generates the name of the new file. In most cases, this will be the end of the new file name. Defaults to a random (v4) UUID.
  • :posix-file-permissions: The new file will be created with these permissions, given as a String as described in str->posix. If not specified, uses the file system default permissions for new files.
  • :warning: :path [DEPRECATED] Previous name for :dir, kept for backwards compatibility. If both :path and :dir are given (don't do that!), :dir is used.

Examples:

  • (create-temp-file)
  • (create-temp-file {:posix-file-permissions "rw-------"})
  • (create-temp-file {:dir (path (cwd) "_workdir") :prefix "process-1-" :suffix "-queue"})
Creates an empty file using [Files/createTempFile](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#createTempFile(java.nio.file.Path,java.lang.String,java.lang.String,java.nio.file.attribute.FileAttribute...)).

This function does not set up any automatic deletion of the files it
creates. Create the file in a [[with-temp-dir]] for that functionality.

Options:
* `:dir`: Directory in which to create the new file. Defaults to default
system temp dir (e.g. `/tmp`); see [[temp-dir]]. Must already exist.
* `:prefix`: Provided as a hint to the process that generates the name of the
new file. In most cases, this will be the beginning of the new file name.
Defaults to a random (v4) UUID.
* `:suffix`: Provided as a hint to the process that generates the name of the
new file. In most cases, this will be the end of the new file name.
Defaults to a random (v4) UUID.
* `:posix-file-permissions`: The new file will be created with these
permissions, given as a String as described in [[str->posix]]. If not
specified, uses the file system default permissions for new files.
* :warning: `:path` **[DEPRECATED]** Previous name for `:dir`, kept
for backwards compatibility. If both `:path` and `:dir` are given (don't do
that!), `:dir` is used.

Examples:
* `(create-temp-file)`
* `(create-temp-file {:posix-file-permissions "rw-------"})`
* `(create-temp-file {:dir (path (cwd) "_workdir") :prefix "process-1-" :suffix "-queue"})`
sourceraw docstring

creation-timeclj

(creation-time f)
(creation-time f {:keys [nofollow-links] :as opts})

Returns creation time of f as FileTime.

See README notes for some details on behaviour.

Returns creation time of `f` as [FileTime](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/attribute/FileTime.html).

See [README notes](/README.md#creation-time) for some details on behaviour.
sourceraw docstring

cwdclj

(cwd)

Returns current working directory as Path

Returns current working directory as `Path`
sourceraw docstring

deleteclj

(delete f)

Deletes f using Files/delete. Returns nil if the delete was successful, throws otherwise. Does not follow symlinks.

Deletes `f` using [Files/delete](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#delete(java.nio.file.Path)).
Returns `nil` if the delete was successful,
throws otherwise. Does not follow symlinks.
sourceraw docstring

delete-if-existsclj

(delete-if-exists f)

Deletes f if it exists via Files/deleteIfExists. Returns true if the delete was successful, false if f didn't exist. Does not follow symlinks.

Deletes `f` if it exists via [Files/deleteIfExists](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#deleteIfExists(java.nio.file.Path)).
Returns `true` if the delete was successful,
`false` if `f` didn't exist. Does not follow symlinks.
sourceraw docstring

delete-on-exitclj

(delete-on-exit f)

Requests delete of file f on exit via File#deleteOnExit. Returns f unaltered.

Requests delete of file `f` on exit via [File#deleteOnExit](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/File.html#deleteOnExit()).
Returns `f` unaltered.
sourceraw docstring

delete-treeclj

(delete-tree root)
(delete-tree root {:keys [force]})

Deletes a file tree root using walk-file-tree. Similar to rm -rf. Does not follow symlinks. force ensures read-only directories/files are deleted. Similar to chmod -R +wx + rm -rf

Deletes a file tree `root` using [[walk-file-tree]]. Similar to `rm -rf`. Does not follow symlinks.
`force` ensures read-only directories/files are deleted. Similar to `chmod -R +wx` + `rm -rf`
sourceraw docstring

directory?clj

(directory? f)
(directory? f {:keys [:nofollow-links]})

Returns true if f is a directory, using Files/isDirectory.

Options:

Returns true if `f` is a directory, using [Files/isDirectory](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#isDirectory(java.nio.file.Path,java.nio.file.LinkOption...)).

Options:
* [`:nofollow-links`](/README.md#nofollow-links)
sourceraw docstring

ends-with?clj

(ends-with? this other)

Returns true if path this ends with path other.

Returns `true` if path `this` ends with path `other`.
sourceraw docstring

exec-pathsclj

(exec-paths)

Returns executable paths (using the PATH environment variable). Same as (split-paths (System/getenv "PATH")).

Returns executable paths (using the `PATH` environment variable). Same
as `(split-paths (System/getenv "PATH"))`.
sourceraw docstring

executable?clj

(executable? f)

Returns true if f has is executable via Files/isExecutable.

Returns true if `f` has is executable via [Files/isExecutable](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#isExecutable(java.nio.file.Path)).
sourceraw docstring

exists?clj

(exists? f)
(exists? f {:keys [:nofollow-links]})

Returns true if f exists via Files/exists.

Options:

Returns true if `f` exists via [Files/exists](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#exists(java.nio.file.Path,java.nio.file.LinkOption...)).

Options:
* [`:nofollow-links`](/README.md#nofollow-links)
sourceraw docstring

expand-homeclj

(expand-home f)

If f begins with a tilde (~), expand the tilde to the value of the user.home system property. If the f 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. Returns a Path

If `f` begins with a tilde (`~`), expand the tilde to the value
of the `user.home` system property. If the `f` 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`. Returns a `Path`
sourceraw docstring

extensionclj

(extension path)

Returns the extension of path via split-ext.

Returns the extension of `path` via [[split-ext]].
sourceraw docstring

fileclj

(file f)
(file f & fs)

Coerces arg(s) into a File, combining multiple paths into one. Multiple-arg versions treat the first argument as parent and subsequent args as children relative to the parent.

Coerces arg(s) into a `File`, combining multiple paths into one.
Multiple-arg versions treat the first argument as parent and subsequent args
as children relative to the parent.
sourceraw docstring

file-nameclj

(file-name x)

Returns the name of the file or directory via File#getName. E.g. (file-name "foo/bar/baz") returns "baz".

Returns the name of the file or directory via [File#getName](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/File.html#getName()).
E.g. (file-name "foo/bar/baz") returns "baz".
sourceraw docstring

file-separatorclj

The system-dependent default name-separator character (as string)

The system-dependent default name-separator character (as string)
sourceraw docstring

file-time->instantclj

(file-time->instant ft)

Converts ft FileTime to an Instant.

Converts `ft` [FileTime](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/attribute/FileTime.html)
to an [Instant](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/Instant.html).
sourceraw docstring

file-time->millisclj

(file-time->millis ft)

Converts ft FileTime to epoch millis (long).

Converts `ft` [FileTime](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/attribute/FileTime.html)
to epoch millis (long).
sourceraw docstring

get-attributeclj

(get-attribute path attribute)
(get-attribute path attribute {:keys [:nofollow-links]})

Return attribute for path via Files/getAttribute

Options:

Return `attribute` for `path` via [Files/getAttribute](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#getAttribute(java.nio.file.Path,java.lang.String,java.nio.file.LinkOption...))

Options:
* [`:nofollow-links`](/README.md#nofollow-links)
sourceraw docstring

globclj

(glob root pattern)
(glob root pattern opts)

Given a file root and glob pattern, returns matches as vector of paths. Patterns containing ** or / will cause a recursive walk over path, unless overriden with :recursive. Similarly: :hidden will be enabled (when not set) when pattern starts with a dot. Glob interpretation is done using the rules described in FileSystem#getPathMatcher

Options:

  • :hidden - match hidden paths. Implied when pattern starts with a dot; otherwise, default to false. Note: on Windows files starting with a dot are not hidden, unless their hidden attribute is set.
  • :follow-links - follow symlinks. Defaults to false.
  • :recursive - force recursive search. Implied when pattern contains ** or /; otherwise, defaults to false.
  • :max-depth - max depth to descend into directory structure, when recursing. Defaults to Integer/MAX_VALUE.

Examples: (fs/glob "." "**.clj")

Given a file `root` and glob `pattern`, returns matches as vector of
paths. Patterns containing `**` or `/` will cause a recursive walk over
path, unless overriden with :recursive. Similarly: :hidden will be enabled (when not set)
when `pattern` starts with a dot.
Glob interpretation is done using the rules described in
[FileSystem#getPathMatcher](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/FileSystem.html#getPathMatcher(java.lang.String))

Options:

* `:hidden` - match hidden paths. Implied when `pattern` starts with a dot;
otherwise, default to false. Note: on Windows files starting with a dot are
not hidden, unless their hidden attribute is set.
* [`:follow-links`](/README.md#follow-links) - follow symlinks. Defaults to false.
* `:recursive` - force recursive search. Implied when `pattern` contains
`**` or `/`; otherwise, defaults to false.
* `:max-depth` - max depth to descend into directory structure, when
recursing. Defaults to Integer/MAX_VALUE.

Examples:
`(fs/glob "." "**.clj")`
sourceraw docstring

gunzipclj

(gunzip gz-file)
(gunzip gz-file dest)
(gunzip gz-file dest {:keys [replace-existing]})

Extracts gz-file to dest directory (default ".").

Options:

  • :replace-existing - true / false: overwrite existing files
Extracts `gz-file` to `dest` directory (default `"."`).

Options:
* `:replace-existing` - `true` / `false`: overwrite existing files
sourceraw docstring

gzipclj

(gzip source-file)
(gzip source-file {:keys [dir out-file] :or {dir "."}})

Gzips source-file and writes the output to dir/out-file.

Options:

  • out-file if not provided, the source-file name with .gz appended is used.
  • dir if not provided, the current directory is used.

Returns the created gzip file.

Gzips `source-file` and writes the output to `dir/out-file`.

Options:
* `out-file` if not provided, the `source-file` name with `.gz` appended is used.
* `dir` if not provided, the current directory is used.

Returns the created gzip file.
sourceraw docstring

hidden?clj

(hidden? f)

Returns true if f is hidden via Files/isHidden.

TIP: some older JDKs can throw on empty-string path (hidden ""). Consider instead checking cwd via (hidden ".").

Returns true if `f` is hidden via [Files/isHidden](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#isHidden(java.nio.file.Path)).

TIP: some older JDKs can throw on empty-string path `(hidden "")`.
Consider instead checking cwd via `(hidden ".")`.
sourceraw docstring

homeclj

(home)
(home user)

With no arguments, returns the current value of the user.home system property as a Path. If a user is passed, returns that user's home directory as found in the parent of home with no args.

With no arguments, returns the current value of the `user.home`
system property as a `Path`. If a `user` is passed, returns that user's home
directory as found in the parent of home with no args.
sourceraw docstring

instant->file-timeclj

(instant->file-time instant)

Converts instant Instant to a FileTime.

Converts `instant` [Instant](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/Instant.html)
to a [FileTime](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/attribute/FileTime.html).
sourceraw docstring

last-modified-timeclj

(last-modified-time f)
(last-modified-time f {:keys [nofollow-links] :as opts})

Returns last modified time of f as a FileTime.

Returns last modified time of `f` as a [FileTime](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/attribute/FileTime.html).
sourceraw docstring

list-dirclj

(list-dir dir)
(list-dir dir glob-or-accept)

Returns all paths in dir as vector. For descending into subdirectories use glob.

  • glob-or-accept - a glob string such as "*.edn" or a (fn accept [^java.nio.file.Path p]) -> truthy
Returns all paths in `dir` as vector. For descending into subdirectories use `glob.`
- `glob-or-accept` - a glob string such as "*.edn" or a `(fn accept [^java.nio.file.Path p]) -> truthy`
sourceraw docstring

list-dirsclj

(list-dirs dirs glob-or-accept)

Similar to list-dir but accepts multiple roots in dirs and returns the concatenated results.

  • glob-or-accept - a glob string such as "*.edn" or a (fn accept [^java.nio.file.Path p]) -> truthy
Similar to list-dir but accepts multiple roots in `dirs` and returns the concatenated results.
- `glob-or-accept` - a glob string such as `"*.edn"` or a `(fn accept [^java.nio.file.Path p]) -> truthy`
sourceraw docstring

matchclj

(match root pattern)
(match root pattern {:keys [hidden follow-links max-depth recursive]})

Given a file root and match pattern, returns matches as vector of paths. Pattern interpretation is done using the rules described in FileSystem#getPathMatcher

Options:

  • :hidden - match hidden paths - note: on Windows paths starting with a dot are not hidden, unless their hidden attribute is set. Defaults to false, i.e. skip hidden files and folders.
  • :follow-links - follow symlinks. Defaults to false.
  • :recursive - match recursively. Defaults to false.
  • :max-depth - max depth to descend into directory structure, when matching recursively. Defaults to Integer/MAX_VALUE.

Examples: (fs/match "." "regex:.*\\.clj" {:recursive true})

Given a file `root` and match `pattern`, returns matches as vector of
paths. Pattern interpretation is done using the rules described in
[FileSystem#getPathMatcher](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/FileSystem.html#getPathMatcher(java.lang.String))

Options:

* `:hidden` - match hidden paths - note: on Windows paths starting with
a dot are not hidden, unless their hidden attribute is set. Defaults to
false, i.e. skip hidden files and folders.
* [`:follow-links`](/README.md#follow-links) - follow symlinks. Defaults to false.
* `:recursive` - match recursively. Defaults to false.
* `:max-depth` - max depth to descend into directory structure, when
matching recursively. Defaults to Integer/MAX_VALUE.

Examples:
`(fs/match "." "regex:.*\\.clj" {:recursive true})`
sourceraw docstring

millis->file-timeclj

(millis->file-time millis)

Converts epoch millis (long) to a FileTime.

Converts epoch millis (long) to a [FileTime](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/attribute/FileTime.html).
sourceraw docstring

modified-sinceclj

(modified-since anchor file-set)

Returns seq of regular files (non-directories, non-symlinks) from file-set that were modified since the anchor path. The anchor path can be a regular file or directory, in which case the recursive max last modified time stamp is used as the timestamp to compare with. The file-set may be a regular file, directory or collection of files (e.g. returned by glob). Directories are searched recursively.

Returns seq of regular files (non-directories, non-symlinks) from `file-set` that were modified since the `anchor` path.
The `anchor` path can be a regular file or directory, in which case
the recursive max last modified time stamp is used as the timestamp
to compare with.  The `file-set` may be a regular file, directory or
collection of files (e.g. returned by glob). Directories are
searched recursively.
sourceraw docstring

moveclj

(move source target)
(move source target {:keys [:replace-existing :atomic-move :nofollow-links]})

Move or rename a file source to a target dir or file via Files/move. Returns target as Path.

Options:

  • replace-existing - overwrite existing target, default false
  • atomic-move - watchers will only see complete target file, default false
  • :nofollow-links
Move or rename a file `source` to a `target` dir or file via [Files/move](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#move(java.nio.file.Path,java.nio.file.Path,java.nio.file.CopyOption...)).
Returns `target` as `Path`.

Options:
* `replace-existing` - overwrite existing `target`, default `false`
* `atomic-move` - watchers will only see complete `target` file, default `false`
* [`:nofollow-links`](/README.md#nofollow-links)
sourceraw docstring

normalizeclj

(normalize f)

Returns normalize Path for f via Path#normalize.

Returns normalize `Path` for `f` via [Path#normalize](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Path.html#normalize()).
sourceraw docstring

ownerclj

(owner f)
(owner f {:keys [:nofollow-links]})

Returns the owner of file f via Files/getOwner. Call str on return value to get the owner name as a string.

Options:

Returns the owner of file `f` via [Files/getOwner](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#getOwner(java.nio.file.Path,java.nio.file.LinkOption...)).
Call `str` on return value to get the owner name as a string.

Options:
* [`:nofollow-links`](/README.md#nofollow-links)
sourceraw docstring

parentclj

(parent f)

Returns parent of f. Akin to dirname in bash.

Returns parent of `f`. Akin to `dirname` in bash.
sourceraw docstring

pathclj

(path f)
(path parent child)
(path parent child & more)

Coerces arg(s) into a Path, combining multiple paths into one. Multiple-arg versions treat the first argument as parent and subsequent args as children relative to the parent.

Coerces arg(s) into a `Path`, combining multiple paths into one.
Multiple-arg versions treat the first argument as parent and subsequent
args as children relative to the parent.
sourceraw docstring

path-separatorclj

The system-dependent path-separator character (as string).

The system-dependent path-separator character (as string).
sourceraw docstring

posix->strclj

(posix->str p)

Converts a set of PosixFilePermission p to a string.

Converts a set of `PosixFilePermission` `p` to a string.
sourceraw docstring

posix-file-permissionsclj

(posix-file-permissions f)
(posix-file-permissions f {:keys [:nofollow-links]})

Returns posix file permissions for f. Use posix->str to view as a string.

Options:

Returns posix file permissions for `f`. Use [[posix->str]] to view as a string.

Options:
* [`:nofollow-links`](/README.md#nofollow-links)
sourceraw docstring

read-all-bytesclj

(read-all-bytes f)

Returns contents of file f as byte array via Files/readAllBytes.

Returns contents of file `f` as byte array via [Files/readAllBytes](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#readAllBytes(java.nio.file.Path)).
sourceraw docstring

read-all-linesclj

(read-all-lines f)
(read-all-lines f {:keys [charset] :or {charset "utf-8"}})

Read all lines from a file f via Files/readAllLines.

Read all lines from a file `f` via [Files/readAllLines](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#readAllLines(java.nio.file.Path,java.nio.charset.Charset)).
sourceraw docstring

read-attributesclj

(read-attributes path attributes)
(read-attributes path attributes {:keys [:nofollow-links :key-fn] :as opts})

Same as read-attributes* but turns attributes for path into a map and keywordizes keys. Keywordizing can be changed by passing a :key-fn in the opts map.

Same as [[read-attributes*]] but turns `attributes` for `path` into a map and keywordizes keys.
Keywordizing can be changed by passing a `:key-fn` in the `opts` map.
sourceraw docstring

read-attributes*clj

(read-attributes* path attributes)
(read-attributes* path attributes {:keys [:nofollow-links]})

Reads attributes for path via Files/readAttributes.

Options:

Reads `attributes` for `path` via [Files/readAttributes](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#readAttributes(java.nio.file.Path,java.lang.Class,java.nio.file.LinkOption...)).

Options:
* [`:nofollow-links`](/README.md#nofollow-links)
sourceraw docstring

(read-link path)

Reads the target of a symbolic link path via Files/readSymbolicLink. The target need not exist.

Reads the target of a symbolic link `path` via [Files/readSymbolicLink](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#readSymbolicLink(java.nio.file.Path)).
The target need not exist.
sourceraw docstring

readable?clj

(readable? f)

Returns true if f is readable via Files/isReadable

Returns true if `f` is readable via [Files/isReadable](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#isReadable(java.nio.file.Path))
sourceraw docstring

real-pathclj

(real-path f)
(real-path f {:keys [:nofollow-links]})

Converts f into real Path via Path#toRealPath.

Options:

Converts `f` into real `Path` via [Path#toRealPath](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Path.html#toRealPath(java.nio.file.LinkOption...)).

Options:
* [`:nofollow-links`](/README.md#nofollow-links)
sourceraw docstring

regular-file?clj

(regular-file? f)
(regular-file? f {:keys [:nofollow-links]})

Returns true if f is a regular file, using Files/isRegularFile.

Options:

Returns true if `f` is a regular file, using [Files/isRegularFile](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#isRegularFile(java.nio.file.Path,java.nio.file.LinkOption...)).

Options:
* [`:nofollow-links`](/README.md#nofollow-links)
sourceraw docstring

relative?clj

(relative? f)

Returns true if f represents a relative path (in other words, is not absolute?).

Returns true if `f` represents a relative path (in other words, is not [[absolute?]]).
sourceraw docstring

relativizeclj

(relativize this other)

Returns relative Path by comparing this with other via Path#relativize.

Returns relative `Path` by comparing `this` with `other` via [Path#relativize](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Path.html#relativize(java.nio.file.Path)).
sourceraw docstring

rootclj

(root path)

Returns root for path as Path, or nil via Path#getRoot.

The return value depends upon the runtime platform.

On Windows, returns Windows specific roots, ex: (replace forward slash with backslash):

  • C:/ for C:/foo/bar
  • C: for C:foo/bar
  • //server/share for //server/share/foo/bar

On Linux and macOS, returns the leading / for anything that looks like an absolute path.

Returns `root` for `path` as `Path`, or `nil` via [Path#getRoot](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Path.html#getRoot()).

The return value depends upon the runtime platform.

On Windows, returns Windows specific roots, ex:
(replace forward slash with backslash):
* `C:/` for `C:/foo/bar`
* `C:`  for `C:foo/bar` 
* `//server/share` for `//server/share/foo/bar`

On Linux and macOS, returns the leading `/` for anything that looks like an absolute path.
sourceraw docstring

same-file?clj

(same-file? this other)

Returns true if this is the same file as other via Files/isSamefile.

Returns `true` if `this` is the same file as `other` via [Files/isSamefile](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#isSameFile(java.nio.file.Path,java.nio.file.Path)).
sourceraw docstring

set-attributeclj

(set-attribute path attribute value)
(set-attribute path attribute value {:keys [:nofollow-links]})

Set attribute for path to value via Files/setAttribute

Set `attribute` for `path` to `value` via [Files/setAttribute](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#setAttribute(java.nio.file.Path,java.lang.String,java.lang.Object,java.nio.file.LinkOption...))
sourceraw docstring

set-creation-timeclj

(set-creation-time f time)
(set-creation-time f time {:keys [nofollow-links] :as opts})

Sets creation time of f to time (epoch millis or FileTime).

Options:

See README notes for some details on behaviour.

Sets creation time of `f` to time (`epoch millis` or [FileTime](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/attribute/FileTime.html)).

Options:
* [`:nofollow-links`](/README.md#nofollow-links)

See [README notes](/README.md#set-creation-time) for some details on behaviour.
sourceraw docstring

set-last-modified-timeclj

(set-last-modified-time f time)
(set-last-modified-time f time {:keys [nofollow-links] :as opts})

Sets last modified time of f to time (epoch millis or FileTime).

Sets last modified time of `f` to `time` (`epoch millis` or [FileTime](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/attribute/FileTime.html)).
sourceraw docstring

set-posix-file-permissionsclj

(set-posix-file-permissions f posix-file-permissions)

Sets posix-file-permissions on f. Accepts a string like "rwx------" or a set of PosixFilePermission.

Sets `posix-file-permissions` on `f`. Accepts a string like `"rwx------"` or a set of `PosixFilePermission`.
sourceraw docstring

sizeclj

(size f)

Returns the size of a file (in bytes).

Returns the size of a file (in bytes).
sourceraw docstring

split-extclj

(split-ext path)
(split-ext path {:keys [ext]})

Splits path on extension. If provided, a specific extension ext, the extension (without dot), will be used for splitting. Directories are not processed.

Splits `path` on extension. If provided, a specific extension `ext`, the
extension (without dot), will be used for splitting.  Directories
are not processed.
sourceraw docstring

split-pathsclj

(split-paths joined-paths)

Splits a joined-paths list given as a string joined by the OS-specific path-separator into a vec of paths. On UNIX systems, the separator is ':', on Microsoft Windows systems it is ';'.

Splits a `joined-paths` list given as a string joined by the OS-specific [[path-separator]] into a vec of paths.
On UNIX systems, the separator is ':', on Microsoft Windows systems it is ';'.
sourceraw docstring

starts-with?clj

(starts-with? this other)

Returns true if path this starts with path other.

Returns `true` if path `this` starts with path `other`.
sourceraw docstring

str->posixclj

(str->posix s)

Converts a string s to a set of PosixFilePermission.

s is a string like "rwx------".

Converts a string `s` to a set of `PosixFilePermission`.

`s` is a string like `"rwx------"`.
sourceraw docstring

strip-extclj

(strip-ext path)
(strip-ext path {:keys [ext] :as opts})

Strips extension for path via split-ext.

Strips extension for `path` via [[split-ext]].
sourceraw docstring

sym-link?clj

(sym-link? f)

Determines if f is a symbolic link via Files/isSymbolicLink.

Determines if `f` is a symbolic link via [Files/isSymbolicLink](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#isSymbolicLink(java.nio.file.Path)).
sourceraw docstring

temp-dirclj

(temp-dir)

Returns java.io.tmpdir property as path.

Returns `java.io.tmpdir` property as path.
sourceraw docstring

unixifyclj

(unixify f)

Returns path as string with Unix-style file separators (/).

Returns path as string with Unix-style file separators (`/`).
sourceraw docstring

unzipclj

(unzip zip-file)
(unzip zip-file dest)
(unzip zip-file dest {:keys [replace-existing extract-fn]})

Unzips zip-file to dest directory (default ".").

Options:

  • :replace-existing - true / false: overwrite existing files
  • :extract-fn - function that decides if the current ZipEntry should be extracted. The function is only called for the file case (not directories) with a map with entries:
    • :entry and the current ZipEntry
    • :name and the name of the ZipEntry (result of calling getName) Extraction only occurs if a truthy value is returned (i.e. not nil/false).
Unzips `zip-file` to `dest` directory (default `"."`).

Options:
* `:replace-existing` - `true` / `false`: overwrite existing files
* `:extract-fn` - function that decides if the current ZipEntry
  should be extracted. The function is only called for the file case
  (not directories) with a map with entries:
  * `:entry` and the current ZipEntry
  * `:name` and the name of the ZipEntry (result of calling `getName`)
  Extraction only occurs if a truthy value is returned (i.e. not
  nil/false).
sourceraw docstring

update-fileclj

(update-file path f & xs)
(update-file path opts f & xs)

Updates the contents of text file path using f applied to old contents and xs. Returns the new contents.

Options:

  • :charset - charset of file, default to "utf-8"
Updates the contents of text file `path` using `f` applied to old contents and `xs`.
Returns the new contents.

Options:
* `:charset` - charset of file, default to "utf-8"
sourceraw docstring

walk-file-treeclj

(walk-file-tree f
                {:keys [:pre-visit-dir :post-visit-dir :visit-file
                        :visit-file-failed :follow-links :max-depth]})

Walks f using Files/walkFileTree.

Options:

  • :follow-links
  • :max-depth maximum directory depth to walk, defaults is unlimited
  • Override default visitor functions via:
    • :pre-visit-dir args [dir attrs]
    • :post-visit-dir args [dir ex]
    • :visit-file args [file attrs]
    • :visit-file-failed args [file ex]

All visitor functions must return one of :continue, :skip-subtree, :skip-siblings or :terminate. A different return value will throw. When not supplied, visitor functions default to (constantly :continue).

Returns f as Path.

Walks `f` using [Files/walkFileTree](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#walkFileTree(java.nio.file.Path,java.util.Set,int,java.nio.file.FileVisitor)).

Options:
* [`:follow-links`](/README.md#follow-links)
* `:max-depth` maximum directory depth to walk, defaults is unlimited 
* Override default visitor functions via:
  * `:pre-visit-dir` args `[dir attrs]`
  * `:post-visit-dir` args `[dir ex]`
  * `:visit-file` args `[file attrs]`
  * `:visit-file-failed` args `[file ex]`

All visitor functions must return one of `:continue`, `:skip-subtree`, `:skip-siblings` or `:terminate`.
A different return value will throw. When not supplied, visitor functions default
to `(constantly :continue)`.

Returns `f` as `Path`.
sourceraw docstring

whichclj

(which program)
(which program opts)

Returns Path to first executable program found in :paths opt, similar to the which Unix command. Default for :paths is (exec-paths).

On Windows, searches for program with filename extensions specified in :win-exts option. Default is ["com" "exe" "bat" "cmd"]. If program already includes an extension from :win-exts, it will be searched as-is first.

When program is a relative or absolute path, :paths option is not consulted. On Windows, the :win-exts variants are still searched. On other OSes, the path for program will be returned if executable, else nil.

Returns `Path` to first executable `program` found in `:paths` `opt`, similar to the `which` Unix command.
Default for `:paths` is ([[exec-paths]]).

On Windows, searches for `program` with filename extensions specified in `:win-exts` option.
Default is `["com" "exe" "bat" "cmd"]`.
If `program` already includes an extension from `:win-exts`, it will be searched as-is first.

When `program` is a relative or absolute path, `:paths` option is not consulted. On Windows, the `:win-exts`
variants are still searched. On other OSes, the path for `program` will be returned if executable,
else `nil`.
sourceraw docstring

which-allclj

(which-all program)
(which-all program opts)

Returns every Path to program found in (exec-paths). See which.

Returns every `Path` to `program` found in ([[exec-paths]]). See [[which]].
sourceraw docstring

windows?clj

(windows?)

Returns true if OS is Windows.

Returns true if OS is Windows.
sourceraw docstring

with-temp-dircljmacro

(with-temp-dir [binding-name] & body)
(with-temp-dir [binding-name options] & body)

Evaluates body with binding-name bound to the result of (create-temp-dir options), then cleans up. See create-temp-dir for valid options.

The directory will be removed with delete-tree on exit from the scope.

Example:

(with-temp-dir [d]
  (let [t (path d "extract")
    (create-dir t)
    (gunzip path-to-zip t)
    (copy (path t "the-one-file-I-wanted.txt") (path permanent-dir "file-I-extracted.txt"))))
;; d no longer exists here
Evaluates body with binding-name bound to the result of `(create-temp-dir
options)`, then cleans up. See [[create-temp-dir]]
for valid `options`.

The directory will be removed with [[delete-tree]] on exit from the scope.

Example:

```
(with-temp-dir [d]
  (let [t (path d "extract")
    (create-dir t)
    (gunzip path-to-zip t)
    (copy (path t "the-one-file-I-wanted.txt") (path permanent-dir "file-I-extracted.txt"))))
;; d no longer exists here
```
sourceraw docstring

writable?clj

(writable? f)

Returns true if f is writable via Files/isWritable

Returns true if `f` is writable via [Files/isWritable](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#isWritable(java.nio.file.Path))
sourceraw docstring

write-bytesclj

(write-bytes path bytes)
(write-bytes path
             bytes
             {:keys [append create truncate-existing write] :as opts})

Writes bytes to path via Files/write.

Options:

  • :create (default true)
  • :truncate-existing (default true)
  • :write (default true)
  • :append (default false)
  • or any java.nio.file.StandardOption.

Examples:

(fs/write-bytes f (.getBytes (String. "foo"))) ;; overwrites + truncates or creates new file
(fs/write-bytes f (.getBytes (String. "foo")) {:append true})
Writes `bytes` to `path` via [Files/write](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#write(java.nio.file.Path,byte%5B%5D,java.nio.file.OpenOption...)).

Options:
* `:create` (default `true`)
* `:truncate-existing` (default `true`)
* `:write` (default `true`)
* `:append` (default `false`)
* or any `java.nio.file.StandardOption`.

Examples:

``` clojure
(fs/write-bytes f (.getBytes (String. "foo"))) ;; overwrites + truncates or creates new file
(fs/write-bytes f (.getBytes (String. "foo")) {:append true})
```
sourceraw docstring

write-linesclj

(write-lines path lines)
(write-lines path lines {:keys [charset] :or {charset "utf-8"} :as opts})

Writes lines, a seqable of strings to path via Files/write.

Options:

  • :charset (default "utf-8")

Open options:

  • :create (default true)
  • :truncate-existing (default true)
  • :write (default true)
  • :append (default false)
  • or any java.nio.file.StandardOption.
Writes `lines`, a seqable of strings to `path` via [Files/write](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#write(java.nio.file.Path,java.lang.Iterable,java.nio.charset.Charset,java.nio.file.OpenOption...)).

Options:
* `:charset` (default `"utf-8"`)

Open options:
* `:create` (default `true`)
* `:truncate-existing` (default `true`)
* `:write` (default `true`)
* `:append` (default `false`)
* or any `java.nio.file.StandardOption`.
sourceraw docstring

xdg-cache-homeclj

(xdg-cache-home)
(xdg-cache-home app)

Path representing the base directory relative to which user-specific non-essential data files should be stored as described in the XDG Base Directory Specification.

Returns path based on the value of env-var XDG_CACHE_HOME (if set and representing an absolute path), else (fs/path (fs/home) ".cache"). When provided, appends app to the path.

Path representing the base directory relative to which user-specific non-essential data files should be stored as described in the [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html).

Returns path based on the value of env-var `XDG_CACHE_HOME` (if set and representing an absolute path), else `(fs/path (fs/home) ".cache")`.
When provided, appends `app` to the path.
sourceraw docstring

xdg-config-homeclj

(xdg-config-home)
(xdg-config-home app)

Path representing the base directory relative to which user-specific configuration files should be stored as described in the XDG Base Directory Specification.

Returns path based on the value of env-var XDG_CONFIG_HOME (if set and representing an absolute path), else (fs/path (fs/home) ".config"). When provided, appends app to the path.

Path representing the base directory relative to which user-specific configuration files should be stored as described in the [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html).

Returns path based on the value of env-var `XDG_CONFIG_HOME` (if set and representing an absolute path), else `(fs/path (fs/home) ".config")`.
When provided, appends `app` to the path.
sourceraw docstring

xdg-data-homeclj

(xdg-data-home)
(xdg-data-home app)

Path representing the base directory relative to which user-specific data files should be stored as described in the XDG Base Directory Specification.

Returns path based on the value of env-var XDG_DATA_HOME (if set and representing an absolute path), else (fs/path (fs/home) ".local" "share"). When provided, appends app to the path.

Path representing the base directory relative to which user-specific data files should be stored as described in the [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html).

Returns path based on the value of env-var `XDG_DATA_HOME` (if set and representing an absolute path), else `(fs/path (fs/home) ".local" "share")`.
When provided, appends `app` to the path.
sourceraw docstring

xdg-state-homeclj

(xdg-state-home)
(xdg-state-home app)

Path representing the base directory relative to which user-specific state files should be stored as described in the XDG Base Directory Specification.

Returns path based on the value of env-var XDG_STATE_HOME (if set and representing an absolute path), else (fs/path (fs/home) ".local" "state"). When provided, appends app to the path.

Path representing the base directory relative to which user-specific state files should be stored as described in the [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html).

Returns path based on the value of env-var `XDG_STATE_HOME` (if set and representing an absolute path), else `(fs/path (fs/home) ".local" "state")`.
When provided, appends `app` to the path.
sourceraw docstring

zipclj

(zip zip-file entries)
(zip zip-file entries opts)

Zips entry or entries into zip-file. An entry may be a file or directory. Directories are included recursively and their names are preserved in the zip file. Currently only accepts relative entries.

Options:

  • :root: directory which will be elided in zip. E.g.: (fs/zip ["src"] {:root "src"})
  • :path-fn: a single-arg function from file system path to zip entry path.
Zips entry or `entries` into `zip-file`. An entry may be a file or
directory. Directories are included recursively and their names are
preserved in the zip file. Currently only accepts relative entries.

Options:
* `:root`: directory which will be elided in zip. E.g.: `(fs/zip ["src"] {:root "src"})`
* `:path-fn`: a single-arg function from file system path to zip entry path.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close