iLua File Module

This module handles file and filesystem operations. Defines file and path namespaces and expands os. All paths are considered to be UTF-8 strings.

File library

File objects extend the stream type.

file.open(filename, mode)
Opens a file in specified mode, which can be a string consisting of "r" (read), "w" (write) and "a" (append) characters. The semantics are as follows:
  • "r" alone has no effect - all files can be read.
  • "w" opens a new or existing file and truncates (clears) it.
  • "rw" opens a new or existing file and keeps its content.
  • "a" places the cursor at the end of file and has no other effect. Use "rwa" to open a file for appending.
file:close()
Close the file. The files are closed automatically when they are garbage collected, but that might take an indeterminate amount of time.
file.attr(filename)
Returns file attributes.
file.copy(src, dst)
Copies file src to location dst, overwriting if a file with that name already exists.
file.copystat(src, dst)
Copies attributes and filetimes of file src to file dst. Returns true on success.
file.move(src, dst)
Moves a file src to location dst, overwriting if a file with that name already exists.
file.remove(filename)
Delete a file. Does not work on directories.
file.setattr(filename, attr)
Set file attributes. Returns true on success.
file.settime(filename, creatin, access, write)
Set file times. Pass nil to keep current value.
file.stat(filename)
Returns attributes, size, creationTime, accessTime, writeTime list. Times are in seconds since January 1, 1601 UTC.
file.temp()
Creates a temporary file that will be deleted after closing.
file.time(filename)
Returns creation, access, write list. Times are in seconds since January 1, 1601 UTC.
file.READONLY
file.HIDDEN
file.SYSTEM
file.DIRECTORY
file.ARCHIVE
file.DEVICE
file.NORMAL
file.TEMPORARY
file.SPARSE_FILE
file.REPARSE_POINT
file.COMPRESSED
file.OFFLINE
file.NOT_INDEXED
file.ENCRYPTED
File attributes.

Filesystem library

os.chdir(path)
Set current directory to path.
os.copytree(src, dst[, mask])
Copy a tree rooted at directory src to location dst. mask is an optional function with signature (dir, name, isdir), where dir is the containing directory, name is a file or subdirectory name, and isdir is a flag specifying whether name is a directory. The function should return true to copy a file, or false to skip it.
os.getcwd()
Returns the absolute path of current directory.
os.listdir(path)
Returns a for iterator that iterates over files in a directory. Returns pairs of name and a flag indicating whether the name specifies a directory.
os.makedirs(path)
Creates a directory and all parent directories if they didn't exist.
os.mkdir(name)
Creates a directory. Parent directory must exist.
os.rmdir(name)
Removes an empty directory.
os.rmtree(path)
Delete a tree rooted at path.
os.walk(path[, reverse])
Returns a for iterator that iterates over all directories in a tree rooted at path. Returns tuples of path, dirs, files, where dirs is a table of all subdirectories and files is a table of all files in the current directory. If reverse is omitted or false, directories are visited before its children directories; otherwise, a directory is visited after all its children are visited. If reverse is false, the dirs table can be modified to remove unwanted directories.

Path library

path.abspath(path)
Returns absolute version of path.
path.basename(path)
Returns the filename portion of path (everything after the last separator; whole string if no separator was found).
path.dirname(path)
Returns the path portion of path (everything up to and including the last separator; empty string if no separator was found).
path.exists(path)
Checks if path specifies an existing file or directory.
path.expandvars(path)
Returns path with strings of the form %variableName% replaced by corresponding environment variables.
path.isabs(path)
Checks if path is an absolute path (starts with a drive letter followed by a colon).
path.isfile(path)
Checks if path specifies an existing file (not directory).
path.isdir(path)
Checks if path specifies an existing directory.
path.join(...)
Joins one or more path components, inserting separators between parts if needed. If any part is an absolute path, all prior parts are discarded.
path.normcase(path)
Returns path converted to lowercase with all separators converted to backslashes.
path.normpath(path)
Returns normalized version of path, obtained by collapsing . and .. components.
path.relpath(to[, from])
Returns the shortest relative path to to from location specified by from (which defaults to current directory).
path.split(path)
Returns the path and filename portions of path, split by the last occurence of separator. The separator itself is not included, unless it follows a drive letter.
path.splitext(path)
Returns path+title and extention portions of path. If no extension is present, returns path, nil. The separating period is included in the extension portion. If the file name starts with period and contains no other periods, the extension is assumed to be empty.
path.sep
Path separator constant, always equals "\\". Changing it has no effect.

RivSoft.net by Riv (riv@rivsoft.net) - All rights reserved