API Documentation

This page documents the functions presented by the lua-fs filesystem extension library.

If you've just started working with the library you should look at how to load and use the extension in your scripts before reading this documentation.

Filesystem Primitives Overview

The filesystem extension implements and exports the following primitives:

chdir()

Change the current working directory (CWD) for the current Lua script.

chmod()

Change the file permissions for the given file or directory.

chown()

Change the owner and group for the specified file or directory.

cwd()

Return the current working directory (CWD).

is_dir()

A utility function to quickly test whether a given name is a directory.

is_file()

A utility function to quickly test whether a given name is a file.

mkdir()

Create a directory.

readdir()

Read all the files contained within a directory.

rmdir()

Delete, or remove, a directory.

stat()

Return detailed information about the given directory, or file.

Detailed API Documentation

chdir()

Usage:

fs.chdir( "/tmp");

This function sets the current directory, or the current working directory, for the script.

See-also cwd()

chmod()

Usage:

fs.chmod( "./a.out", 755 );

This function sets the permissions to the specified item to the given octal string.

See-also chown()

chown()

Usage:

fs.chown("/bin/sh", "root", "root");
fs.chown( "/bin/sh", 0, 0 );

This function changes the owner and group of the specified item. The username or group name (second parameter) may be specified either as integers or as names which will be searched for in /etc/passwd.

See-also chmod()

cwd()

Usage:

dir = fs.cwd();
fs.chown( "/bin/sh", 0, 0 );

Find, and return, the current working dir.

See-also chdir()

is_dir()

Usage:

ret = fs.is_dir( "/etc" );

detect whether the specified item is a directory or not. Return 'true' if it is, 'false' otherwise.

See-also is_file(), stat()

is_file()

Usage:

ret = fs.is_file( "/etc/passwd" );

detect whether the specified item is a file or not. Return 'true' if it is, 'false' otherwise.

See-also is_dir(), stat()

mkdir()

Usage:

ret = fs.mkdir( "/tmp/bar" );

Create the named directory.

See-also rmdir()

readdir()

Usage:

entries = fs.readdir( "/etc" );

Read and return a table containing all the directory entries beneath the given directory name. (Not recursively.)

rmdir()

Usage:

entries = fs.rmdir( "/tmp/foo" );

Delete the specified directory entry.

See-also mkdir()

stat()

Usage:

info = fs.stat( "/etc/passwd" );

Return a table of information about the specified directory entry. The table has keys as follows:

  • Owner information:
    • uid - UID of the owner.
    • gid - GID of the owner
  • Time Information
    • access - Last Access time.
    • change - Last status change time.
    • modification - Last modification time.
  • Misc. Information
    • ino - Inode number.
    • dev - Device.
    • mode - Permissions.
    • type - Entry type:
      • file.
      • socket.
      • directory.
      • & etc.
    • nlink - Number of links to the file.
    • rdev - Device type.
    • size - Size of the file.

See-also is_dir(), is_file()