(util file) - File operation utility library

Library (util file)

This library provides file operation utilities which is not exported from (sagittarius) library.

File to Scheme object operations

reader must be a procedure accept one argument which is a port. path must be a string indicating existing file.

Returns a list which elements are read by reader from the given _path_file. reader reads the file contents until it reads EOF object.

The keyword argument transcoder can specify which transcoder will be used to open a port. It must be either #f or transcoder. The default value is the value (native-transcoder) returns.

Thin wrapper of file->list. The procedures defined as following;

(file->list `read/ss` _path_)

(file->list `get-line` _path_)

respectively.

Reads all file contents indicated path as a string and return it.

Reads all file contents indicated path as a bytevector and return it.

Temporary directory operations

Returns operating system specific temporary directory path.

If optional argument path is given, the procedure replace the temporary directory path.

Creates temporary file and returns 2 values. One is the port, the other one is created file path.

The created temporary file won't be deleted automatically so it is users responsibility to delete.

Path operations

path must be a string.

Decompose the given path to directory path, base name, and extension then returns these decomposed elements as 3 values.

The returning value can be #f if the path does not contains corresponding element.

Returns the extension of given path. If it does not contains extension then the procedure returns #f.

Removes extension from given path and return it.

Returns the basename of given path. If it does not contains basename then the procedure returns #f.

target must be a string indicating existing file system path.

Find files from target if it's a directory and return the found files as a list.

Keyword arguments:

pattern

Specifies the file pattern to be returned. This can be either string or regular expression pattern object.

all

When this keyword argument is #t, then returns all files including hidden files which file name starting with .. If this is #f, the procedure excludes hidden files.

physical

If this is #t, then the proc is only given either directory or file. No symbolic likes are given.

sort

This specifies how to sort the result list. If the value is #f, then the result order is unspecified.

recursive

If this keyword argument is #t then the procedure finds files recursively, otherwise only the first target directory.

_ (stop-on-file #f) (all #t) (recursive #t)

path must be a string indicating existing file path. _proc_must be a procedure accepts 2 arguments, a path string and a symbol. The given symbol can be directory, symbolic-link or file.

Apply given proc to the found paths starting from path and returns unspecified value. The second argument of proc indicates the file type with following meaning;

directory

The path is a directory.

symbolic-link

The path is a symbolic link.

file

The path is a file

The keyword arguments:

file-only

If this is #t, then the proc is only given a file. Otherwise all file types.

absolute-path

If this is #t, then the proc is given absolute path. Otherwise only the filename.

stop-on-false

If this is #t, then when proc returns #f the process will stop. Otherwise it continues the process.

The rest of the keyword arguments are the same as find-files.

_ (recursive #t)

path must be a string indicating existing file path. _proc_must be a procedure accepts 2 arguments, a path string and a symbol. The given symbol can be directory, symbolic-link or file.

Process the path string starting from path with given proc and returns a list which elements are the result value of proc.

The keyword arguments are the same as path-for-each.

Re-exported procedure from (sagittarius) for convenience. See Sagittarius extensions.

paths must be list of strings.

Compose given list to platform specific path. This procedure doesn't put path separator at the end of composed string.

Directory operations

Re-exported procedures from (sagittarius) for convenience. See Sagittarius extensions.

Convenient procedures to create or delete directories.

These are the same as UNIX command mkdir -p and rm -rf, respectively.

src and dst must be string and src must indicates an existing path.

Copies src directory to dst. Keyword argument excludes must be a list of string and the procedure won't copy files which contain the excludes string(s).

The options is passed to path-for-each.