Fs Api Documentation

Version: 1.5.0

me.raynes.fs

File system utilities in Clojure

*cwd*

dynamic

Current working directory. This cannot be changed in the JVM. Changing this will only change the working directory for functions in this library.

absolute

(absolute path)

Return absolute file.

absolute?

(absolute? path)

Return true if path is absolute.

base-name

(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.

chdir

(chdir path)

set!s the value of *cwd* to path. Only works inside of with-mutable-cwd

child-of?

(child-of? p c)

Takes two paths and checks to see if the first path is a parent of the second.

chmod

(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

copy

(copy from to)

Copy a file from from to to. Return to.

copy+

(copy+ src dest)

Copy src to dest, create directories if needed.

copy-dir

(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-dir-into

(copy-dir-into from to)

Copy directory into another directory if destination already exists.

create

(create f)

Create a new file.

delete

(delete path)

Delete path.

delete-dir

(delete-dir root & link-options)

Delete a directory tree. Optional link-options may be provided to determine whether or not to follow symbolic links.

directory?

(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.

ephemeral-dir

(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).

ephemeral-file

(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).

exec

(exec & body)

Execute a shell command in the current directory

executable?

(executable? path)

Return true if path is executable.

exists?

(exists? path)

Return true if path exists.

expand-home

(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.

extension

(extension path)

Return the extension part of a file.

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.

file?

(file? path)

Return true if path is a file.

find-files

(find-files path pattern)

Find files matching given pattern.

find-files*

(find-files* path pred)

Find files in path by pred.

glob

(glob pattern)(glob root pattern)

Returns files matching glob pattern.

hidden?

(hidden? path)

Return true if path is hidden.

home

(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.

iterate-dir

(iterate-dir path)

Return a sequence [root dirs files], starting from path in depth-first order

link?

(link? path)

Return true if path is a link. Requires Java version 7 or greater.

list-dir

(list-dir path)

List files and directories under path.

mkdir

(mkdir path)

Create a directory.

mkdirs

(mkdirs path)

Make directory tree.

mod-time

(mod-time path)

Return file modification time.

move

(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.

name

(name path)

Return the name part of a file.

normalized

(normalized path)

Return normalized (canonical) file.

ns-path

(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.

parent

(parent path)

Return the parent path.

parents

(parents f)

Get all the parent directories of a path.

path-ns

(path-ns path)

Takes a path to a Clojure file and constructs a namespace symbol out of the path.

readable?

(readable? path)

Return true if path is readable.

rename

(rename old-path new-path)

Rename old-path to new-path. Only works on files.

size

(size path)

Return size (in bytes) of file.

split

(split path)

Split path to components.

split-ext

(split-ext path)

Returns a vector of [name extension].

temp-dir

(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).

temp-file

(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).

temp-name

(temp-name prefix)(temp-name prefix suffix)

Create a temporary file name like what is created for temp-file and temp-dir.

tmpdir

(tmpdir)

The temporary file directory looked up via the java.io.tmpdir system property. Does not create a temporary directory.

touch

(touch path & [time])

Set file modification time (default to now). Returns path.

unix-root

The root of a unix system is /, nil on Windows

walk

(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.

with-cwd

macro

(with-cwd cwd & body)

Execute body with a changed working directory.

with-mutable-cwd

macro

(with-mutable-cwd & body)

Execute the body in a binding with *cwd* bound to *cwd*. This allows you to change *cwd* with set!.

writeable?

(writeable? path)

Return true if path is writeable.