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 objects extend the stream
type.
file.open(filename, mode)
file:close()
file.attr(filename)
file.copy(src, dst)
src
to location dst
, overwriting if a file with that name already exists.
file.copystat(src, dst)
src
to file dst
. Returns true
on success.
file.move(src, dst)
src
to location dst
, overwriting if a file with that name already exists.
file.remove(filename)
file.setattr(filename, attr)
true
on success.
file.settime(filename, creatin, access, write)
nil
to keep current value.
file.stat(filename)
attributes, size, creationTime, accessTime, writeTime
list. Times are in seconds since January 1, 1601 UTC.
file.temp()
file.time(filename)
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
os.chdir(path)
path
.
os.copytree(src, dst[, mask])
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()
os.listdir(path)
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)
os.mkdir(name)
os.rmdir(name)
os.rmtree(path)
path
.
os.walk(path[, reverse])
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.abspath(path)
path
.
path.basename(path)
path
(everything after the last separator; whole string if no separator was found).
path.dirname(path)
path
(everything up to and including the last separator; empty string if no separator was found).
path.exists(path)
path
specifies an existing file or directory.
path.expandvars(path)
path
with strings of the form %variableName%
replaced by corresponding environment variables.
path.isabs(path)
path
is an absolute path (starts with a drive letter followed by a colon).
path.isfile(path)
path
specifies an existing file (not directory).
path.isdir(path)
path
specifies an existing directory.
path.join(...)
path.normcase(path)
path
converted to lowercase with all separators converted to backslashes.
path.normpath(path)
path
, obtained by collapsing .
and ..
components.
path.relpath(to[, from])
to
from location specified by from
(which defaults to current directory).
path.split(path)
path
, split by the last occurence of separator. The separator itself is not included,
unless it follows a drive letter.
path.splitext(path)
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
"\\"
. Changing it has no effect.