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.
(absolute? path)
Return true if path
is absolute.
Return true if `path` is absolute.
(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 from to)
Copy a file from from
to to
. Return to
.
Copy a file from `from` to `to`. Return `to`.
(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.
(delete-dir root & link-options)
Delete a directory tree. Optional link-options may be provided to determine whether or not to follow symbolic links.
Delete a directory tree. Optional [link-options](http://docs.oracle.com/javase/7/docs/api/java/nio/file/LinkOption.html) may be provided to determine whether or not to follow symbolic links.
(directory? path & link-options)
Return true if path
is a directory, false otherwise.
Optional
link-options
may be provided to determine whether or not to follow symbolic
links.
Return true if `path` is a directory, false otherwise. Optional [link-options](http://docs.oracle.com/javase/7/docs/api/java/nio/file/LinkOption.html) may be provided to determine whether or not to follow symbolic links.
(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
(executable? path)
Return true if path
is executable.
Return true if `path` is executable.
(exists? path)
Return true if path
exists.
Return true if `path` exists.
(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.
(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? path)
Return true if path
is a file.
Return true if `path` is a file.
(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`.
(glob pattern)
(glob root pattern)
Returns files matching glob pattern.
Returns files matching glob pattern.
(hidden? path)
Return true if path
is hidden.
Return true if `path` is hidden.
(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
(link new-file existing-file)
Create a "hard" link from path to target. Requires Java version 7 or greater. The arguments are in the opposite order from the link(2) system call.
Create a "hard" link from path to target. Requires Java version 7 or greater. The arguments are in the opposite order from the link(2) system call.
(link? path)
Return true if path
is a link.
Requires Java version 7 or greater.
Return true if `path` is a link. Requires Java version 7 or greater.
(list-dir path)
List files and directories under path
.
List files and directories under `path`.
(mod-time path)
Return file modification time.
Return file modification time.
(move source target & copy-options)
Move or rename a file to a target file. Requires Java version 7 or greater. Optional copy-options may be provided.
Move or rename a file to a target file. Requires Java version 7 or greater. Optional [copy-options](http://docs.oracle.com/javase/7/docs/api/java/nio/file/CopyOption.html) may be provided.
(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-sym-link path)
Return the target of a 'soft' link. Requires Java version 7 or greater.
Return the target of a 'soft' link. Requires Java version 7 or greater.
(readable? path)
Return true if path
is readable.
Return true if `path` is readable.
(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.
(size path)
Return size (in bytes) of file.
Return size (in bytes) of file.
(split-ext path)
Returns a vector of [name extension]
.
Returns a vector of `[name extension]`.
(sym-link path target)
Create a "soft" link from path
to target
.
Requires Java version 7 or greater.
Create a "soft" link from `path` to `target`. Requires Java version 7 or greater.
(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
(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!`.
(writeable? path)
Return true if path
is writeable.
Return true if `path` is writeable.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close