3.43. kink/io/FILE

Mod to operate files in the filesystem.

3.43.1. FILE.open_to_read(Path [[$config = {}]])

Opens the file and return an input.

$config must take a Conf val. The conf val has .on_cannot_open($oco) method and .buffer([[Buf_size = 2048]]) method. If $config is not given, the conf val is kept as the default.

If .on_cannot_open is called and the file cannot be opened, $oco is called with a message str. If .on_cannot_open is not called and the file cannot be opened, an exception is raised.

If Conf.buffer is called, the input is buffered with the Buf_size.

3.43.2. FILE.open_to_scan(Path Encoding [[$config = {}]])

Opens the file and return a scanner.

$config must take a Conf val. The conf val has .on_cannot_open($oco) method and .buffer([[Buf_size = 2048]]) method.

If the file cannot be opened, $oco is called with a message str. If .on_cannot_open is not called, and the file cannot be opened, an exception is raised.

If Conf.buffer is called, the backing input is buffered with the Buf_size.

3.43.3. FILE.open_to_write(Path [[$config = {}]])

Opens the file and returns the output.

$config must take a Conf val. The Conf val has Conf.append method, Conf.on_cannot_open($oco) method, and Conf.buffer([[Buf_size = 2048]]) method.

If Conf.append is called, the bytes are written to the end of the file. Otherwise, the bytes are written to the beginning.

If the file cannot be opened, $oco is called with a message str. If $oco is not given, and the file cannot be opened, an exception is raised.

If Conf.buffer is called, the output is buffered with the Buf_size.

3.43.4. FILE.open_to_print(Path Encoding_name New_line ...[$config = {}])

FILE.open_to_print opens the file and returns the printer.

$config must take a Conf val. The Conf val has Conf.flush_on_print method, Conf.append method, Conf.on_cannot_open($oco) method, and Conf.buffer([[Buf_size = 2048]]) method.

If Conf.flush_on_print is called, the backing output is flushed on each invocation of .print and .print_line methods.

If Conf.append is called, the texts are written to the end of the file. Otherwise, the texts are written to the beginning.

If the file cannot be opened, $oco is called with a message str. If $oco is not given, and the file cannot be opened, an exception is raised.

If Conf.buffer is called, the output is buffered with the Buf_size.

3.43.5. FILE.mkdir(Path ...[$on_error])

Makes a directory on the Path.

If an IO error occurs, and $on_error is not given, an exception is raised.

If an IO error occurs, and $on_error is given, this fun tail-calls $on_error with an error message.

3.43.6. FILE.rm(Path [[$on_error]])

Removes a file or an empty directory.

If an IO error occurs, and $on_error is not given, an exception is raised.

If an IO error occurs, and $on_error is given, this fun tail-calls $on_error with an error message.

3.43.7. FILE.cp(Src_path Dest_path [[$on_error]])

Copies a file on Src_path to a file Dest_path.

Src_path must be an existing file, and must not be a symlink or a directory.

Dest_path must be a path which is not regarded by the filesystem as the same file.

If no entry exists on Dest_path, the fun tries to make a new file.

If Dest_path is an existing file or symlink, the file is overwritten.

If Dest_path is a dir, the fun causes an error.

If an IO error occurs, and $on_error is not given, an exception is raised.

If an IO error occurs, and $on_error is given, this fun tail-calls $on_error with an error message.

3.43.8. FILE.mv(Src_path Dest_path [[$on_error]])

Moves a file, directory or symlink from Src_path, to Dest_path.

Src_path must be an existing entry.

Dest_path must not be an existing entry, except if the Src_path and Dest_path is the same entry, in which case the fun has no effect.

If an IO error occurs, and $on_error is not given, an exception is raised.

If an IO error occurs, and $on_error is given, this fun tail-calls $on_error with an error message.

3.43.9. FILE.ls(Dir_path [[$on_error]])

Returns a vec of the paths of the entries in the directory on Dir_path. The paths are obtained resolving the entries against Dir_path.

If an IO error occurs, and $on_error is not given, an exception is raised.

If an IO error occurs, and $on_error is given, this fun tail-calls $on_error with an error message.

3.43.12. FILE.realpath(Path [[$on_error]])

Returns the absolute real path of the Path, resolving symlinks, links such as '..', and duplicated path separators.

If an IO error occurs, and $on_error is not given, an exception is raised.

If an IO error occurs, and $on_error is given, this fun tail-calls $on_error with an error message.

3.43.13. FILE.basename(Path)

Returns the last part of the path.

If the Path does not contain the basename, the fun returns an empty str.

3.43.14. FILE.dirname(Path)

Returns the path except for the basename from the Path.

If the Path does not contain the basename, the fun returns the path which is semantically equivalent to Path.

3.43.15. FILE.resolve(Base_path Top_path)

Resolves Top_path against Base_path, and returns the result path.

3.43.16. FILE.pwd

Returns the path of the current directory.

3.43.17. FILE.exist?(Path)

Returns true if a file or a directory exists on the Path, following symlinks. Returns false if it does not exist, or the existence cannot be determined.

3.43.18. FILE.file?(Path)

Returns true if a regular file exists on the Path. Returns false if it does not exist, or the existence cannot be determined.

3.43.19. FILE.dir?(Path)

Returns true if a directory exists on the Path. Returns false if it does not exist, or the existence cannot be determined.