LC.fs.*

The module LC.fs provides methods for management of files and directories.

LC.fs.basename(filename)
Arguments
  • filename (String) – file name to extract basename from

Returns

base name (file name without path)

LC.fs.copy(sourcefile, destfile)
Arguments
  • sourcefile (String) – source file name

  • destfile (String) – destination file name

Returns

true or false + error message

Copy the file sourcefile to destfile, keeping all file attributes (owner, permissions, modification time).

LC.fs.dirname(filename)
Arguments
  • filename (String) – file name to extract directory name from

Returns

directory name (without file name)

LC.fs.filecount(path)
Arguments
  • path (String) – directory name to count files in

Returns

number of files in that directory, or false + error message

Return the number of files and directories in path (excluding . and ..). Non-recursive.

LC.fs.glob(pattern)
Arguments
  • pattern (String) – filename pattern to match

Returns

array of matched file names

Build a list of file names which match pattern (e.g. /etc/liveconfig/lua.d/*.lua). If no matching files are found, an empty list is returned. The results are sorted alphabetically.

LC.fs.is_dir(name)
Arguments
  • name (String) – filename to check

Returns

true or false

Return true if name is a directory.

LC.fs.is_file(name)
Arguments
  • name (String) – filename to check

Returns

true or false

Return true if name is a regular file.

Arguments
  • name (String) – filename to check

Returns

true or false

Return true if name is a symbolic link.

LC.fs.mkdir(name)
Arguments
  • name (String) – directory name to create

Returns

true or false + error message

Create a new directory.

LC.fs.mkdir_rec(name)
Arguments
  • name (String) – directory name to create

Returns

true or false + error message

Create a new directory. If one or more of the parent directories don’t exist, they’re also created.

LC.fs.parse_ini(filename)
Arguments
  • filename (String) – name of file to parse

Returns

table with key-value-pairs of .ini content

This function parses the given file (.ini format) and returns the contents as key-value-pairs. If an error occurs, it returns nil and an error string.

LC.fs.rename(oldname, newname)
Arguments
  • oldname (String) – file or directory to rename

  • newname (String) – new name

Returns

true or false + error message

Rename a file or a directory from oldname to newname.

LC.fs.setperm(name, mode, user, group)
Arguments
  • name (String) – file or directory name

  • mode (String) – new file mode (octal value, must be submitted as string!)

  • user (String) – file owner (user)

  • group (String) – file owner (group)

Returns

true or false + error message

Change the permissions for the file or directory name. The new permissions must be submitted as string with an octal value (e.g. "0755"), and user/group is the new file owner name.

LC.fs.setUserQuota(user, path, limit)
Arguments
  • user (String) – user to set quota for

  • path (String) – file system (path) to set quota

  • limit (Number) – quota limit (kB)

Returns

true or false + error message

Set the diskspace quota for user user on the device mounted at path to limit kilobyte.

Example: set limit for user v12007 on /var/www/v12007 to 200 MB (=204800 kB):

LC.fs.setUserQuota("v12007", "/var/www/v12007", 204800)
LC.fs.setGroupQuota(group, path, limit)
Arguments
  • group (String) – group to set quota for

  • path (String) – file system (path) to set quota

  • limit (Number) – quota limit (kB)

Returns

true or false + error message

Set the diskspace quota for group group on the device mounted at path to limit kilobyte.

LC.fs.getUserQuota(user, path)
Arguments
  • user (String) – user to get quota for

  • path (String) – file system (path)

Returns

table or nil + error message (see description)

Get the diskspace quota for user user on the device mounted at path. The results are returned as table with the following fields:

  • kb_soft soft limit in kilobytes (1024 bytes)

  • kb_hard hard limit

  • kb_used disk space actually used

  • n_soft soft limit of inodes (number of files & directories)

  • n_hard hard limit of inodes

  • n_used number of inodes in use

If an error occured, nil and an error message (String) is returned.

LC.fs.getGroupQuota(group, path)
Arguments
  • group (String) – group to get quota for

  • path (String) – file system (path)

Returns

table or nil + error message (see description)

Get the diskspace quota for group group on the device mounted at path. The result table is analogous to LC.fs.getUserQuota().


Last updated on Jun 29, 2020.
next: LC.log.*
previous: LC.expect.*