babashka.fsabsolute?- Returnstrueifpathis absolute via Path#isAbsolute.absolutize- Convertspathinto an absolute path via Path#toAbsolutePath.canonicalize- Returns the canonical path forpathvia File#getCanonicalPath.components- Returns a seq of paths for all components ofpath.copy- Copiessource-filetotarget-pathdir or file via Files/copy.copy-tree- Copies entire file tree fromsource-dirtotarget-dir.create-dir- Createsdirvia Files/createDirectory.create-dirs- Createsdirvia Files/createDirectories.create-file- Creates emptyfilevia Files/createFile.create-link- Creates a new hardlink(directory entry) for anexisting-filevia Files/createLink.create-sym-link- Creates a symboliclinktotarget-pathvia Files/createSymbolicLink.create-temp-dir- Returns path to directory created via Files/createTempDirectory.create-temp-file- Returns path to empty file created via Files/createTempFile.creation-time- Returns creation time ofpathas FileTime.cwd- Returns current working directory path.delete- Deletespathvia Files/delete.delete-if-exists- Deletespathif it exists via Files/deleteIfExists.delete-on-exit- Requests delete ofpathon exit via File#deleteOnExit.delete-tree- Deletes the file tree atroot-pathusingwalk-file-tree.directory?- Returnstrueifpathis a directory via Files/isDirectory.ends-with?- Returnstrueifthis-pathends withother-pathvia Path#endsWith.exec-paths- Returns a vector of command search paths (from thePATHenvironment variable).executable?- Returnstrueifpathis executable via Files/isExecutable.exists?- Returnstrueifpathexists via Files/exists.expand-home- Returnspathreplacing~(tilde) with home dir.extension- Returns the extension ofpathviasplit-ext.file- Coercespath(s) into aFile, combining multiple paths into one.file-name- Returns the name of the file or directory forpathvia File#getName.file-separator- The system-dependent default path component separator character (as string) via File/separator.file-time->instant- ConvertsftFileTime to an Instant.file-time->millis- ConvertsftFileTime to epoch milliseconds (long).get-attribute- Returns value ofattributeforpathvia Files/getAttribute.glob- Returns a vector of paths matching globpattern(on path and filename) relative toroot-dir.gunzip- Extractsgz-filetotarget-dir.gzip- Gzipssource-fileto:dir/:out-file.hidden?- Returnstrueifpathis hidden via Files/isHidden.home- Returns home dir path.instant->file-time- ConvertsinstantInstant to a FileTime.last-modified-time- Returns last modified time ofpathas FileTime.list-dir- Returns a vector of all paths indir.list-dirs- Similar tolist-dirbut accepts multiple roots indirsand returns the concatenated results.match- Returns a vector of paths matchingpattern(on path and filename) relative toroot-dir.millis->file-time- Converts epoch milliseconds (long) to a FileTime.modified-since- Returns seq of regular files (non-directories, non-symlinks) frompath-setthat were modified since theanchor-path.move- Moves or renames dir or file atsource-pathtotarget-pathdir or file via Files/move.normalize- Returns normalized path forpathvia Path#normalize.owner- Returns the owner ofpathvia Files/getOwner.parent- Returns parent path ofpathvia Path#getParent.path- Coercespath(s) into aPath, combining multiple paths into one.path-separator- The system-dependent path-separator character (as string) via File/pathSeparator.posix->str- Converts a set ofPosixFilePermissionpto a string, like"rwx------"via PosixFilePermissions/toString.posix-file-permissions- Returns a set ofPosixFilePermissionforpathvia Files/getPosixFilePermissions.read-all-bytes- Returns contents offileas byte array via Files/readAllBytes.read-all-lines- Returns contents offileas a vector of lines via Files/readAllLines.read-attributes- Same asread-attributes*but returns requestedattributesforpathas a map with keywordized attribute keys.read-attributes*- Returns requestedattributesforpathvia Files/readAttributes.read-link- Returns the immediate target ofsym-link-pathvia Files/readSymbolicLink.readable?- Returnstrueifpathis readable via Files/isReadable.real-path- Convertspathinto real path via Path#toRealPath.regular-file?- Returnstrueifpathis a regular file via Files/isRegularFile.relative?- Returnstrueifpathis relative (in other words, is notabsolute?).relativize- Returnsother-pathrelative tobase-pathvia Path#relativize.root- Returns root path forpath, ornil, via Path#getRoot.same-file?- Returnstrueifthis-pathis the same file asother-pathvia Files/isSamefile.set-attribute- Setsattributeforpathtovaluevia Files/setAttribute.set-creation-time- Sets creationtimeofpath.set-last-modified-time- Sets last modifiedtimeofpath.set-posix-file-permissions- Setsposix-file-permissionsonpathvia Files/setPosixFilePermissions.size- Returns the size ofpathin bytes.split-ext- Splitspathon extension.split-paths- Splitsjoined-pathsstring into a vector of paths by OS-specificpath-separator.starts-with?- Returnstrueifthis-pathstarts withother-pathvia Path#startsWith.str->posix- Converts stringsto a set ofPosixFilePermissionvia PosixFilePermissions/fromString.strip-ext- Strips extension frompathviasplit-ext.sym-link?- Returnstrueifpathis a symbolic link via Files/isSymbolicLink.temp-dir- Returnsjava.io.tmpdirproperty as path.touch- Updates last modified time ofpathto:time, creatingpathas a file if it does not exist.unixify- Returnspathas string with Unix-style file separators (/).unzip- Unzipszip-filetotarget-dir(default".").update-file- Updates the contents of textfilewith result of applying functionfwith old contents and argsxs.walk-file-tree- Walkspathvia Files/walkFileTree.which- Returns path to first executableprogramfound in:paths, similar to thewhichUnix command.which-all- Returns a vector of every path toprogramfound in (exec-paths).windows?- Returnstrueif OS is Windows.with-temp-dir- Evaluates body withtemp-dirbound to the result of(create-temp-dir opts).writable?- Returnstrueifpathis writable via Files/isWritable.write-bytes- Writesbytestofilevia Files/write.write-lines- Writeslines, a seqable of strings, tofilevia Files/write.xdg-cache-home- Returns path to user-specific non-essential data as described in the XDG Base Directory Specification.xdg-config-home- Returns path to user-specific configuration files as described in the XDG Base Directory Specification.xdg-data-home- Returns path to user-specific data files as described in the XDG Base Directory Specification.xdg-state-home- Returns path to user-specific state files as described in the XDG Base Directory Specification.zip- Zipspath-or-pathsintozip-file.
(absolute? path)Function.
Returns true if path is absolute via Path#isAbsolute.
(absolutize path)Function.
Converts path into an absolute path via Path#toAbsolutePath.
(canonicalize path)
(canonicalize path {:keys [:nofollow-links]})Function.
Returns the canonical path for path via File#getCanonicalPath.
Options:
:nofollow-links- when set, falls back onabsolutize+normalize.
This function can be used as an alternative to real-path which requires files to exist.
(components path)Function.
Returns a seq of paths for all components of path.
i.e.: split on the file-separator.
(copy source-file target-path)
(copy source-file target-path {:keys [replace-existing copy-attributes nofollow-links]})Function.
Copies source-file to target-path dir or file via Files/copy.
Options:
:replace-existing:copy-attributes:nofollow-links- used to determine to copy symbolic link itself or not.
Returns target-path.
(copy-tree source-dir target-dir)
(copy-tree source-dir target-dir {:keys [:replace-existing :copy-attributes :nofollow-links], :as opts})Function.
Copies entire file tree from source-dir to target-dir. Creates target-dir if needed.
Options:
- same as
copy :posix-file-permissions- string format unix-like system permissions passed tocreate-dirswhen creatingtarget-dir.
(create-dir dir)
(create-dir dir {:keys [:posix-file-permissions]})Function.
Creates dir via Files/createDirectory.
Does not create parents.
Returns dir.
Options:
:posix-file-permissions- string format for unix-like system permissions fordir, as described instr->posix. Affected by umask.
(create-dirs dir)
(create-dirs dir {:keys [:posix-file-permissions]})Function.
Creates dir via Files/createDirectories.
Also creates parents if needed.
Does not throw an exception if the dirs exist already. Similar to mkdir -p shell command.
Returns dir.
Options:
:posix-file-permissions- string format for unix-like system permissions fordir, as described instr->posix. Affected by umask.
(create-file file)
(create-file file {:keys [:posix-file-permissions]})Function.
Creates empty file via Files/createFile.
Returns file.
Options:
:posix-file-permissions- string format for unix-like system permissions forfile, as described instr->posix. Affected by umask.
(create-link link existing-file)Function.
Creates a new hard link (directory entry) for an existing-file via Files/createLink.
Returns link.
(create-sym-link link target-path)Function.
Creates a symbolic link to target-path via Files/createSymbolicLink.
Returns link.
As of this writing, JDKs do not recognize empty-string target-path "" as the cwd.
Consider instead using a target-path of "." to link to the cwd.
(create-temp-dir)
(create-temp-dir {:keys [:dir :prefix :posix-file-permissions], :as opts})Function.
Returns path to directory created via 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); seetemp-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- string format unix-like system permissions as described instr->posixfor new directory. If not specified, uses the file system default permissions for new directories. Affected by umask.⚠️ :path- [DEPRECATED] previous name for:dir, kept for backwards compatibility. If both:pathand:dirare given (don't do that!),:diris used.
Examples:
(create-temp-dir)(create-temp-dir {:posix-file-permissions "rwx------"})(create-temp-dir {:dir (path (cwd) "_workdir") :prefix "process-1-"})
(create-temp-file)
(create-temp-file {:keys [:dir :prefix :suffix :posix-file-permissions], :as opts})Function.
Returns path to empty file created via 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); seetemp-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- string format unix-like system permissions for new file, as described instr->posix. If not specified, uses the file system default permissions for new files. Affected by umask.⚠️ :path- [DEPRECATED] Previous name for:dir, kept for backwards compatibility. If both:pathand:dirare given (don't do that!),:diris used.
Examples:
(create-temp-file)(create-temp-file {:posix-file-permissions "rw-------"})(create-temp-file {:dir (path (cwd) "_workdir") :prefix "process-1-" :suffix "-queue"})
(creation-time path)
(creation-time path {:keys [nofollow-links], :as opts})Function.
Returns creation time of path as FileTime.
See README notes for some details on behaviour.
See also: set-creation-time, last-modified-time, file-time->instant, file-time->millis
(cwd)Function.
Returns current working directory path.
(delete path)Function.
Deletes path via Files/delete.
Returns nil if the delete was successful,
throws otherwise. Does not follow symlinks.
(delete-if-exists path)Function.
Deletes path if it exists via Files/deleteIfExists.
Returns true if the delete was successful,
false if path didn't exist. Does not follow symlinks.
(delete-on-exit path)Function.
Requests delete of path on exit via File#deleteOnExit.
Returns path.
(delete-tree root-path)
(delete-tree root-path {:keys [force]})Function.
Deletes the file tree at root-path using walk-file-tree. Similar to rm -rf shell command. Does not follow symlinks.
Options:
:force- iftrueforces deletion of read-only files/directories. Similar tochmod -R +wx+rm -rfshell commands.
(directory? path)
(directory? path {:keys [:nofollow-links]})Function.
Returns true if path is a directory via Files/isDirectory.
Options:
(ends-with? this-path other-path)Function.
Returns true if this-path ends with other-path via Path#endsWith.
See also: starts-with?
(exec-paths)Function.
Returns a vector of command search paths (from the PATH environment variable). Same
as (split-paths (System/getenv "PATH")).
(executable? path)Function.
Returns true if path is executable via Files/isExecutable.
(exists? path)
(exists? path {:keys [:nofollow-links]})Function.
Returns true if path exists via Files/exists.
Options:
(expand-home path)Function.
Returns path replacing ~ (tilde) with home dir.
If path:
- does not start with
~, returnspath. - starts with
~thenfile-separator,~is replaced with(home). e.g.,~/foo->/home/myuser/foo - starts with
~then some other chars, those other chars are assumed to be a username, then naively expanded to(home username). e.g.,~someuser/foo->/home/someuser/foo
See also: home
(extension path)Function.
Returns the extension of path via split-ext.
(file path)
(file path & paths)Function.
Coerces path(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.
(file-name path)Function.
Returns the name of the file or directory for path via File#getName.
E.g. (file-name "foo/bar/baz") returns "baz".
The system-dependent default path component separator character (as string) via File/separator.
(file-time->instant ft)Function.
Converts ft FileTime
to an Instant.
(file-time->millis ft)Function.
Converts ft FileTime
to epoch milliseconds (long).
(get-attribute path attribute)
(get-attribute path attribute {:keys [:nofollow-links]})Function.
Returns value of attribute for path via Files/getAttribute.
Options:
(glob root-dir pattern)
(glob root-dir pattern opts)Function.
Returns a vector of paths matching glob pattern (on path and filename) relative to root-dir.
Patterns containing ** or / will cause a recursive walk under
root-dir, unless overriden with :recursive false. Similarly, :hidden will be automatically enabled
when pattern starts with a dot.
Glob interpretation is done using the rules described in
FileSystem#getPathMatcher
Options:
:hidden- match hidden paths. Impliedtruewhenpatternstarts with a dot; otherwise, defaults tofalse. Note: on Windows files starting with a dot are not hidden, unless their hidden attribute is set.:follow-links- follow symlinks. Defaults tofalse.:recursive- impliedtruewhenpatterncontains**or/; otherwise, defaults tofalse.true-patternis matched against all descendant files and directories underroot-dirfalse-patternis matched only against immediate children underroot-dir
:max-depth- max depth to descend into directory structure, when recursing. Defaults toInteger/MAX_VALUE.
Examples:
(fs/glob "." "**.clj")- finds.cljfiles and dirs under.dir and its subdirs(fs/glob "." "**.clj" {:recursive false})- finds.cljfiles and dirs immediately under.dir only(fs/glob "." "*.clj" {:recursive true})- finds.cljfiles and dirs immediately under.only (patternlacks directory wildcards)
If on macOS, see note on glob
See also: match
(gunzip gz-file)
(gunzip gz-file target-dir)
(gunzip gz-file target-dir {:keys [replace-existing]})Function.
Extracts gz-file to target-dir.
If target-dir not specified (or nil) defaults to gz-file dir.
File is extracted to target-dir with gz-file file-name without .gz extension.
Creates target-dir dir(s) if necessary.
The gz-file is not deleted.
Options:
:replace-existing- whentrueoverwrites existing file
See also: gzip
(gzip source-file)
(gzip source-file {:keys [dir out-file]})Function.
Gzips source-file to :dir/:out-file.
Does not store the source-file name in the .gz file.
The source-file is not deleted.
Options:
:dir(s) - created if necessary. If not specified, defaults tosource-filedir.:out-file- if not specified, defaults tosource-filefile-namewith.gzextension.
Returns the created gzip file.
See also: gunzip
(hidden? path)Function.
Returns true if path is hidden via Files/isHidden.
TIP: some older JDKs can throw on empty-string path (hidden "").
Consider instead checking cwd via (hidden ".").
(home)
(home user)Function.
Returns home dir path.
With no arguments, returns the current value of the user.home
system property. If a user is passed, returns that user's home
directory as found in the parent of home with no args.
(instant->file-time instant)Function.
Converts instant Instant
to a FileTime.
(last-modified-time path)
(last-modified-time path {:keys [nofollow-links], :as opts})Function.
Returns last modified time of path as FileTime.
See also: set-last-modified-time, creation-time, file-time->instant, file-time->millis
(list-dir dir)
(list-dir dir glob-or-accept)Function.
Returns a vector of all paths in dir. For descending into subdirectories use glob.
glob-or-accept- aglobstring such as"*.edn"or a(fn accept [^java.nio.file.Path p]) -> truthy
(list-dirs dirs glob-or-accept)Function.
Similar to list-dir but accepts multiple roots in dirs and returns the concatenated results.
glob-or-accept- aglobstring such as"*.edn"or a(fn accept [^java.nio.file.Path p]) -> truthy
(match root-dir pattern)
(match root-dir pattern {:keys [hidden follow-links max-depth recursive]})Function.
Returns a vector of paths matching pattern (on path and filename) relative to root-dir.
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 tofalse, i.e. skip hidden files and folders.:follow-links- follow symlinks. Defaults to false.:recursivetrue-patternis matched against all descendant files and directories underroot-dirfalse(default) -patternis matched only against immediate children underroot-dir
:max-depth- max depth to descend into directory structure, when matching recursively. Defaults toInteger/MAX_VALUE.
Examples:
(fs/match "." "regex:.*\\.clj" {:recursive true})
See also: glob
(millis->file-time millis)Function.
Converts epoch milliseconds (long) to a FileTime.
(modified-since anchor-path path-set)Function.
Returns seq of regular files (non-directories, non-symlinks) from path-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 path-set may be a regular file, directory or
collection of paths (e.g. as returned by glob). Directories are
searched recursively.
(move source-path target-path)
(move source-path target-path {:keys [:replace-existing :atomic-move]})Function.
Moves or renames dir or file at source-path to target-path dir or file via Files/move.
If target-path is a directory, moves source-path under target-path.
Never follows symbolic links.
Returns target-path.
Options:
replace-existing- overwrite existingtarget-path, defaultfalseatomic-move- watchers will only see completetarget-pathfile, defaultfalse
(normalize path)Function.
Returns normalized path for path via Path#normalize.
(owner path)
(owner path {:keys [:nofollow-links]})Function.
Returns the owner of path via Files/getOwner.
Call str on return value to get the owner name as a string.
Options:
(parent path)Function.
Returns parent path of path via Path#getParent.
Akin to dirname in bash.
(path path)
(path parent child)
(path parent child & more)Function.
Coerces path(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.
The system-dependent path-separator character (as string) via File/pathSeparator.
(posix->str p)Function.
Converts a set of PosixFilePermission p to a string, like "rwx------" via PosixFilePermissions/toString.
See also: str->posix
(posix-file-permissions path)
(posix-file-permissions path {:keys [:nofollow-links]})Function.
Returns a set of PosixFilePermission for path via Files/getPosixFilePermissions.
Use posix->str to convert to a string.
Options:
See also: set-posix-file-permissions
(read-all-bytes file)Function.
Returns contents of file as byte array via Files/readAllBytes.
(read-all-lines file)
(read-all-lines file {:keys [charset], :or {charset "utf-8"}})Function.
Returns contents of file as a vector of lines via Files/readAllLines.
Options:
:charset- defaults to"utf-8"
(read-attributes path attributes)
(read-attributes path attributes {:keys [:nofollow-links :key-fn], :as opts})Function.
Same as read-attributes* but returns requested attributes for path as a map with keywordized attribute keys.
Options:
:key-fn- optionally override keywordizing function with your own.:nofollow-links
(read-attributes* path attributes)
(read-attributes* path attributes {:keys [:nofollow-links]})Function.
Returns requested attributes for path via Files/readAttributes.
Options:
(read-link sym-link-path)Function.
Returns the immediate target of sym-link-path via Files/readSymbolicLink.
The target need not exist.
(readable? path)Function.
Returns true if path is readable via Files/isReadable
(real-path path)
(real-path path {:keys [:nofollow-links]})Function.
Converts path into real path via Path#toRealPath.
Options:
(regular-file? path)
(regular-file? path {:keys [:nofollow-links]})Function.
Returns true if path is a regular file via Files/isRegularFile.
Options:
(relative? path)Function.
Returns true if path is relative (in other words, is not absolute?).
(relativize base-path other-path)Function.
Returns other-path relative to base-path via Path#relativize.
Examples:
(fs/relativize "a/b" "a/b/c/d")=>c/d(fs/relativize "a/b/c/d" "a/b")=>../..
(root path)Function.
Returns root path for 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:/forC:/foo/barC:forC:foo/bar//server/sharefor//server/share/foo/bar
On Linux and macOS, returns the leading / for anything that looks like an absolute path.
(same-file? this-path other-path)Function.
Returns true if this-path is the same file as other-path via Files/isSamefile.
(set-attribute path attribute value)
(set-attribute path attribute value {:keys [:nofollow-links]})Function.
Sets attribute for path to value via Files/setAttribute.
(set-creation-time path time)
(set-creation-time path time {:keys [nofollow-links], :as opts})Function.
Sets creation time of path.
time can be epoch milliseconds (long),
FileTime,
or Instant.
Options:
See README notes for some details on behaviour.
See also: creation-time
(set-last-modified-time path time)
(set-last-modified-time path time {:keys [nofollow-links], :as opts})Function.
Sets last modified time of path.
time can be epoch milliseconds (long),
FileTime,
or Instant.
See also: last-modified-time
(set-posix-file-permissions path posix-file-permissions)Function.
Sets posix-file-permissions on path via Files/setPosixFilePermissions.
Accepts a string like "rwx------" or a set of PosixFilePermission.
See also: posix-file-permissions
(size path)Function.
Returns the size of path in bytes.
(split-ext path)
(split-ext path {:keys [ext]})Function.
Splits path on extension. Returns [name ext].
Leading directories in path are not processed.
Options:
:ext- split on specified extension (do not include a leading dot)
Examples:
(fs/split-ext "foo.bar.baz")=>["foo.bar" "baz"](fs/split-ext "foo.bar.baz" {:ext "bar.baz"})=>["foo" "bar.baz"](fs/split-ext "foo.bar.baz" {:ext "png"})=>["foo.bar.baz" nil]
(split-paths joined-paths)Function.
Splits joined-paths string into a vector of paths by OS-specific path-separator.
(starts-with? this-path other-path)Function.
Returns true if this-path starts with other-path via Path#startsWith.
See also: ends-with?
(str->posix s)Function.
Converts string s to a set of PosixFilePermission via PosixFilePermissions/fromString.
s is a string like "rwx------".
See also: posix->str
(strip-ext path)
(strip-ext path {:keys [ext], :as opts})Function.
Strips extension from path via split-ext.
(sym-link? path)Function.
Returns true if path is a symbolic link via Files/isSymbolicLink.
(temp-dir)Function.
Returns java.io.tmpdir property as path.
(touch path)
(touch path {:keys [time nofollow-links], :as opts})Function.
Updates last modified time of path to :time, creating path as a file if it does not exist.
If path is deleted by some other process/thread before :time is set,
a NoSuchFileException will be thrown. Callers can, if their use case requires it,
implement their own retry loop.
Options:
:time- last modified time (epoch milliseconds (long), Instant, or FileTime), defaults to current time:nofollow-links
(unixify path)Function.
Returns path as string with Unix-style file separators (/).
(unzip zip-file)
(unzip zip-file target-dir)
(unzip zip-file target-dir {:keys [replace-existing extract-fn]})Function.
Unzips zip-file to target-dir (default ".").
Options:
:replace-existing-true/false: overwrite existing files:extract-fn- function that decides if the current ZipEntry should be extracted. Extraction only occurs if a truthy value is returned (i.e. not nil/false). The function is only called for files (not directories) with a single map arg::entry- the currentZipEntry:name- the name of theZipEntry(result of callinggetName)
See also: zip.
(update-file file f & xs)
(update-file file opts f & xs)Function.
Updates the contents of text file with result of applying function f with old contents and args xs.
Returns the new contents.
Options:
:charset- charset of file, default to "utf-8"
(walk-file-tree path {:keys [:pre-visit-dir :post-visit-dir :visit-file :visit-file-failed :follow-links :max-depth]})Function.
Walks path via 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 path.
(which program)
(which program opts)Function.
Returns path to first executable program found in :paths, similar to the which Unix command.
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.
Options:
:paths- paths to search, default is return of (exec-paths):win-exts- active on Windows only. Searches forprogramwith filename extensions specified in:win-extsoption. Ifprogramalready includes an extension from:win-exts, it will be searched as-is first. Default is["com" "exe" "bat" "cmd"].
(which-all program)
(which-all program opts)Function.
Returns a vector of every path to program found in (exec-paths). See which.
(windows?)Function.
Returns true if OS is Windows.
(with-temp-dir [temp-dir] & body)
(with-temp-dir [temp-dir opts] & body)Macro.
Evaluates body with temp-dir bound to the result of (create-temp-dir opts).
By default, the temp-dir will be removed with delete-tree on exit from the scope.
Options:
- see
create-temp-dirfor options that control directory creation :keep- iftruedoes not delete the directory on exit from macro 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
(writable? path)Function.
Returns true if path is writable via Files/isWritable
(write-bytes file bytes)
(write-bytes file bytes {:keys [append create truncate-existing write], :as opts})Function.
Writes bytes to file via Files/write.
Options:
:create- (defaulttrue):truncate-existing- (defaulttrue):write- (defaulttrue):append- (defaultfalse)- 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})(write-lines file lines)
(write-lines file lines {:keys [charset], :or {charset "utf-8"}, :as opts})Function.
Writes lines, a seqable of strings, to file via Files/write.
Options:
:charset- (default"utf-8")
Open options:
:create- (defaulttrue):truncate-existing- (defaulttrue):write- (defaulttrue):append- (defaultfalse)- or any
java.nio.file.StandardOption.
(xdg-cache-home)
(xdg-cache-home app)Function.
Returns path to user-specific non-essential data as described in the XDG Base Directory Specification.
Uses env-var XDG_CACHE_HOME (if set and representing an absolute path), else (fs/path (fs/home) ".cache").
When provided, appends app to the returned path.
(xdg-config-home)
(xdg-config-home app)Function.
Returns path to user-specific configuration files as described in the XDG Base Directory Specification.
Uses env-var XDG_CONFIG_HOME (if set and representing an absolute path), else (fs/path (fs/home) ".config").
When provided, appends app to the returned path.
(xdg-data-home)
(xdg-data-home app)Function.
Returns path to user-specific data files as described in the XDG Base Directory Specification.
Uses 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 returned path.
(xdg-state-home)
(xdg-state-home app)Function.
Returns path to user-specific state files as described in the XDG Base Directory Specification.
Uses 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 returned path.
(zip zip-file path-or-paths)
(zip zip-file path-or-paths opts)Function.
Zips path-or-paths into zip-file. A path may be a file or
directory. Directories are included recursively and their names are
preserved in the zip file. Currently only accepts relative paths.
Options:
:root- optional directory to be elided inzip-fileentries. E.g.:(fs/zip ["src"] {:root "src"}):path-fn- an optional custom path conversion function. A single-arg function called for each file system path returning the path to be used for the corresponding zip entry.
See also: unzip.