Module lfs
LuaFileSystem is a Lua library developed to complement the set of functions related to file systems offered by the standard Lua distribution. LuaFileSystem offers a portable way to access the underlying directory structure and file attributes.
Functions
| attributes (filepath, aname) | Returns a table with the file attributes corresponding to filepath (or nil followed by an error message in case of error). |
| chdir (path) | Changes the current working directory to the given path.Returns true in case of success or nil plus an error string. |
| currentdir () | Returns a string with the current working directory or nil plus an error string. |
| dir (path) | Lua iterator over the entries of a given directory. |
| lock (filehandle, mode, start, length) | Locks a file or a part of it. |
| mkdir (dirname) | Creates a new directory. |
| rmdir (dirname) | Removes an existing directory. |
| touch (filepath, atime, mtime) | Set access and modification times of a file. |
| unlock (filehandle, start, length) | Unlocks a file or a part of it. |
Functions
- attributes (filepath, aname)
-
Returns a table with the file attributes corresponding to
filepath(ornilfollowed 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 tolfs.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; attributemodeis a string, all the others are numbers, and the time related attributes use the same time reference ofos.time.Parameters
- filepath:
- aname:
- chdir (path)
-
Changes the current working directory to the given
path.
Returnstruein case of success ornilplus an error string.Parameters
- path:
- currentdir ()
-
Returns a string with the current working directory or
nilplus an error string. - dir (path)
-
Lua iterator over the entries of a given directory. Each time the iterator is called it returns a string with an entry of the directory;
nilis returned when there is no more entries. Raises an error ifpathis not a directory.Parameters
- path:
- lock (filehandle, mode, start, length)
-
Locks a file or a part of it. This function works on open files; the file handle should be specified as the first argument. The string
modecould be eitherr(for a read/shared lock) orw(for a write/exclusive lock). The optional argumentsstartandlengthcan be used to specify a starting point and its length; both should be numbers.
Returnstrueif the operation was successful; in case of error, it returnsnilplus an error string.Parameters
- filehandle:
- mode:
- start:
- length:
- mkdir (dirname)
-
Creates a new directory. The argument is the name of the new directory.
Returnstrueif the operation was successful; in case of error, it returnsnilplus an error string.Parameters
- dirname:
- rmdir (dirname)
-
Removes an existing directory. The argument is the name of the directory.
Returnstrueif the operation was successful; in case of error, it returnsnilplus an error string.Parameters
- dirname:
- touch (filepath, atime, mtime)
-
Set access and modification times of a file. This function is a bind to
utimefunction. 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 functionos.date). If the modification time is omitted, the access time provided is used; if both times are omitted, the current time is used.
Returnstrueif the operation was successful; in case of error, it returnsnilplus an error string.Parameters
- filepath:
- atime:
- mtime:
- unlock (filehandle, start, length)
-
Unlocks a file or a part of it. This function works on open files; the file handle should be specified as the first argument. The optional arguments
startandlengthcan be used to specify a starting point and its length; both should be numbers.
Returnstrueif the operation was successful; in case of error, it returnsnilplus an error string.Parameters
- filehandle:
- start:
- length: