LuaFileSystem offers the following functions:
lfs.attributes (filepath [, aname])
filepath
(or nil
followed by an error message
in case of error).
If the second optional argument is given, then only the value of the
named attribute is returned (this use is equivalent to
lfs.attributes(filepath).aname
, but the table is not created
and only one attribute is retrieved from the O.S.).
The attributes are described as follows;
attribute mode
is a string, all the others are numbers,
and the time related attributes use the same time reference of
os.time
:
dev
ino
mode
file
, directory
, link
, socket
,
named pipe
, char device
, block device
or
other
)nlink
uid
gid
rdev
dev
access
modification
change
size
blocks
blksize
stat
internally thus if the given
filepath
is a symbolic link, it is followed (if it points to
another link the chain is followed recursively) and the information
is about the file it refers to.
To obtain information about the link itself, see function
lfs.symlinkattributes.
lfs.chdir (path)
path
.true
in case of success or nil
plus an
error string.lfs.lock_dir(path, [seconds_stale])
path
if it does not
exist and returns the lock. If the lock already exists checks if
it's stale, using the second parameter (default for the second
parameter is INT_MAX
, which in practice means the lock will never
be stale. To free the the lock call lock:free()
. lfs.currentdir ()
nil
plus an error string.iter, dir_obj = lfs.dir (path)
dir_obj
it returns a directory entry's name as a string, or
nil
if there are no more entries. You can also iterate by calling dir_obj:next()
, and
explicitly close the directory before the iteration finished with dir_obj:close()
.
Raises an error if path
is not a directory.
lfs.lock (filehandle, mode[, start[, length]])
mode
could be either
r
(for a read/shared lock) or w
(for a
write/exclusive lock). The optional arguments start
and length
can be used to specify a starting point and
its length; both should be numbers.true
if the operation was successful; in
case of error, it returns nil
plus an error string.
lfs.link (old, new[, symlink])
lfs.mkdir (dirname)
true
if the operation was successful;
in case of error, it returns nil
plus an error string.
lfs.rmdir (dirname)
true
if the operation was successful;
in case of error, it returns nil
plus an error string.lfs.setmode (file, mode)
binary
or text
.
Returns the previous mode string for the file. On non-Windows platforms, where the two modes are identical,
setting the mode has no effect, and the mode is always returned as binary
.
lfs.symlinkattributes (filepath [, aname])
lfs.attributes
.
lfs.touch (filepath [, atime [, mtime]])
utime
function. The first argument is the
filename, the second argument (atime
) is the access time,
and the third argument (mtime
) is the modification time.
Both times are provided in seconds (which should be generated with
Lua standard function os.time
).
If the modification time is omitted, the access time provided is used;
if both times are omitted, the current time is used.true
if the operation was successful;
in case of error, it returns nil
plus an error string.
lfs.unlock (filehandle[, start[, length]])
start
and
length
can be used to specify a starting point and its
length; both should be numbers.true
if the operation was successful;
in case of error, it returns nil
plus an error string.