io.randomseed.utils.fs

added in 1.0.0

Random utils, filesystem utilities.

abs-pathname

(abs-pathname path)

Returns an absolute pathname string. Relative paths are prefixed with the user’s home directory.

absolute-path?

(absolute-path? pathname)

Returns true if pathname represents an absolute path.

basename

(basename f)

Returns the filename component (without directory) of f.

empty-str-ary

Single-element String array used as varargs placeholder for Paths/get.

exists?

(exists? filename)

Returns true if the file exists.

extension

(extension f)

Returns the file extension (without the dot) of f, or nil if none.

file

(file fname)

Coerces fname to a java.io.File. Returns nil when fname is nil.

get-java-classpath-folders

(get-java-classpath-folders)

Lists all directories the exist in Java classpath as a sequence of strings. Returns nil if there are none.

get-java-property

(get-java-property s)

Returns the value of the Java system property named s, or nil.

home-dir-pathname

(home-dir-pathname)(home-dir-pathname & paths)

For the given pathnames creates a pathname expressed as a string by prefixing them with user’s home directory obtained from the Java property user.dir with all parts joined using current path name separator.

mapv-java-properties

(mapv-java-properties v)

Applies parse-java-properties to each element of vector v, returning a new vector. Returns v unchanged when it is falsy.

parse-java-properties

(parse-java-properties s)

Replaces all ${property.name} placeholders in string s with their Java system property values.

parse-java-property

(parse-java-property s)

Resolves a single ${...} placeholder string to its Java system property value.

prop-pathname

(prop-pathname prop)(prop-pathname prop paths)

For the given Java property name and optional path names creates a path name expressed as a string by prefixing them with the directory obtained from a property with all parts joined using pathname separator.

prop-regex

Regex matching ${property.name} placeholders in strings.

read-lines

(read-lines filename)(read-lines n filename)

Read first n lines from a file. If the pathname is relative it will be relative to user’s home directory.

read-preferences

(read-preferences filename)

Reads the given preferences file. If the path is relative it will be relative to user’s home directory.

relative-path?

Returns true if pathname represents a relative path.

resource-exists?

(resource-exists? r)

Returns true if a classpath resource named r exists.

resource-file

(resource-file resource)

Returns a java.io.File object for the existing resource of the given name.

resource-pathname

(resource-pathname)(resource-pathname & paths)

For the given pathnames creates a pathname expressed as a string which resides within one of the Java resource directories. The path must exist to be returned.

user-dir-pathname

(user-dir-pathname)(user-dir-pathname & paths)

For the given pathnames creates a pathname expressed as a string by prefixing them with user’s directory (typically a project directory) obtained from the Java property user.dir with all parts joined using current path name separator.

with-ns-loading

(with-ns-loading op k & more)(with-ns-loading k)

Executes the given function op and passes it a key or a sequence given as k and additional, optional arguments. Before that happens it will get all identifiers from the sequence (or check if the given single k is an identifier) and try to load their namespaces if the identifier(s) is/are fully qualified.

write-preferences

(write-preferences filename data)

Writes the given preference file. If the path is relative it will be relative to user’s home directory.