Module fs

Utility functions for operations on a file system and paths.

Extends LuaFileSystem module.

Note: This module is not part of public API!

Functions

absolute_path (path, relative_to) Converts the path to an absolute path.
dirname (path) Returns the directory name of the path, i.e.
is_binary_file (filename) Checks if the specified file is a binary file (i.e.
is_dir (path) Returns true if there's a directory on the path, false otherwise.
is_file (path) Returns true if there's a file on the path, false otherwise.
path_join (...) Joins the given path components using platform-specific separator.
read_file (filename, mode) Reads the specified file and returns its content as string.
walk_dir (dir_path) Traverses all files under the specified directory recursively.


Functions

absolute_path (path, relative_to)
Converts the path to an absolute path.

Relative paths are referenced from the current working directory of the process unless relative_to is given, in which case it will be used as the starting point. If the given pathname starts with a ~ it is NOT expanded, it is treated as a normal directory name.

Parameters:

  • path string The path name to convert.
  • relative_to optional string The path to prepend when making path absolute. Defaults to the current working directory.

Returns:

    string An absolute path name.
dirname (path)
Returns the directory name of the path, i.e. all the path's components except the last one.

Parameters:

Returns:

    string or nil The directory name, or nil if the path has only one component (e.g. /foo or foo).
is_binary_file (filename)
Checks if the specified file is a binary file (i.e. not textual).

Parameters:

  • filename string Path of the file.

Returns:

    bool true if the file is binary, false otherwise.

Or

  1. nil
  2. string An error message.
is_dir (path)
Returns true if there's a directory on the path, false otherwise.

Parameters:

Returns:

    bool
is_file (path)
Returns true if there's a file on the path, false otherwise.

Parameters:

Returns:

    bool
path_join (...)
Joins the given path components using platform-specific separator.

Parameters:

  • ... string The path components.

Returns:

    string
read_file (filename, mode)
Reads the specified file and returns its content as string.

Parameters:

  • filename string Path of the file to read.
  • mode string The mode in which to open the file, see io.open.

Returns:

    string A content of the file.

Or

  1. nil
  2. string An error message.
walk_dir (dir_path)
Traverses all files under the specified directory recursively.

Parameters:

  • dir_path string Path of the directory to traverse.

Returns:

    coroutine A coroutine that yields file path and its attributes.
generated by LDoc 1.4.6