Version 3.69 of MUSHclient adds a new function to the "utils" table, which reads an entire directory on your PC into a Lua table, based on the wildcard you supply.
For example:
Example output:
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.
For example:
t, e = utils.readdir ("c:/mushclient/plugins/*.xml")
assert (t, e) -- raises error on failure
for k, v in pairs (t) do
Tell (k)
if (v.directory) then
Tell (" (dir) ")
end -- if directory
Tell (" size ", v.size, " bytes, ")
Note (os.date ("%c", v.write_time))
end -- for
Example output:
ShowActivity.xml size 1429 bytes, 03/23/04 11:06:54
Slow_speedwalk.xml size 9655 bytes, 10/24/05 08:58:07
Automap.xml size 19944 bytes, 03/26/04 14:20:11
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:
- size - file size in bytes
- create_time - creation time (except for FAT filesystems, where it is omitted)
- access_time - last access time (except for FAT filesystems, where it is omitted)
- write_time - time written
- archive - true if archive. Set whenever the file is changed, and cleared by the BACKUP command.
- hidden - hidden file. Not normally seen with the DIR command
- normal - normal file. File can be read or written to without restriction.
- readonly - read-only. File cannot be opened for
writing, and a file with the same name cannot be created.
- directory - Subdirectory.
- system - system file. Not normally seen with the DIR command.
By detecting suddirectories you could conceivably recurse and find the contents of subdirectories as well.