utils.readdir

Read a disk directory into a table

Prototype

t = utils.readdir (s)

Description

You can use utils.readdir to read an entire directory on your PC into a Lua table, based on the wildcard you supply.


For example:

t, e = utils.readdir ("c:/mushclient/plugins/*.xml")

assert (t, e) -- raises error on failure
If the directory specification is matched, the result from the call is a table of directory items, keyed by the filename. If the directory specification cannot be matched, or is invalid, it returns nil followed by an error message. You can simply test for non-nil, or call "assert" to report the error.

For each file in the directory (that matches the wildcard) the following is returned: By detecting suddirectories you could conceivably recurse and find the contents of subdirectories as well.

Lua functions

Topics