=head1 NAME lfs - file system operations (LuaFileSystem) =head1 OVERVIEW LuaFileSystem is a Lua (L) 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. It was developed for Lua 5.0. Version 1.2 follows the package model (L) for Lua 5.1 (see section Installation for more details). =head1 EXAMPLES =head2 Directory iterator The following example iterates over a directory and recursively lists the attributes for each file inside it. require"lfs" function attrdir (path) for file in lfs.dir(path) do if file ~= "." and file ~= ".." then local f = path..'/'..file print ("\t "..f) local attr = lfs.attributes (f) assert (type(attr) == "table") if attr.mode == "directory" then attrdir (f) else for name, value in pairs(attr) do print (name, value) end end end end end attrdir (".") =head1 DOWNLOAD LuaFileSystem source can be downloaded from its Lua Forge (L) page. If you are using LuaBinaries (L) Release 2 a Windows binary version of LuaFileSystem can also be found at the LuaForge page. =head1 INSTALLATION LuaFileSystem follows the package model (L) for Lua 5.1, therefore it should be "installed". Refer to Compat-5.1 configuration section about how to install the compiled binary properly. The compiled binary should be copied to a directory in your C. Windows users can use the binary version of LuaFileSystem (C) available at LuaForge (L). =head1 REFERENCE LuaFileSystem offers the following functions: =head2 C lfs.attributes (filepath [, aname]) Returns a table with the file attributes corresponding to C (or C 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 C, but the table is not created and only one attribute is retrieved from the O.S.). The attributes are described as follows; attribute C is a string, all the others are numbers, and the time related attributes use the same time reference of C: =over 4 =item dev on Unix systems, this represents the device that the inode resides on. On Windows systems, represents the drive number of the disk containing the file =item ino on Unix systems, this represents the inode number. On Windows systems this has no meaning =item mode string representing the associated protection mode (the values could be C, C, C, C, C, C, C or C) =item nlink number of hard links to the file =item uid user-id of owner (Unix only, always 0 on Windows) =item gid group-id of owner (Unix only, always 0 on Windows) =item rdev on Unix systems, represents the device type, for special file inodes. On Windows systems represents the same as C =item access time of last access =item modification time of last data modification =item change time of last file status change =item size file size, in bytes =item blocks block allocated for file; (Unix only) =item blksize optimal file system I/O blocksize; (Unix only) =back =head2 C lfs.chdir (path) Changes the current working directory to the given C. Returns C in case of success or C plus an error string. =head2 C lfs.currentdir () Returns a string with the current working directory or C plus an error string. =head2 C lfs.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; C is returned when there is no more entries. Raises an error if C is not a directory. =head2 C lfs.lock (filehandle, mode[, start[, length]]) Locks a file or a part of it. This function works on I; the file handle should be specified as the first argument. The string C could be either C (for a read/shared lock) or C (for a write/exclusive lock). The optional arguments C and C can be used to specify a starting point and its length; both should be numbers. Returns C if the operation was successful; in case of error, it returns C plus an error string. =head2 C lfs.mkdir (dirname) Creates a new directory. The argument is the name of the new directory. Returns C if the operation was successful; in case of error, it returns C plus an error string. =head2 C lfs.rmdir (dirname) Removes an existing directory. The argument is the name of the directory. Returns C if the operation was successful; in case of error, it returns C plus an error string. =head2 C lfs.touch (filepath [, atime [, mtime]]) Set access and modification times of a file. This function is a bind to C function. The first argument is the filename, the second argument (C) is the access time, and the third argument (C) is the modification time. Both times are provided in seconds (which should be generated with Lua standard function C). If the modification time is omitted, the access time provided is used; if both times are omitted, the current time is used. Returns C if the operation was successful; in case of error, it returns C plus an error string. lfs.unlock (filehandle[, start[, length]]) Unlocks a file or a part of it. This function works on I; the file handle should be specified as the first argument. The optional arguments C and C can be used to specify a starting point and its length; both should be numbers. Returns C if the operation was successful; in case of error, it returns C plus an error string. =head1 CONTACT For more information please contact us (info-NO-SPAM-THANKS@keplerproject.org). Comments are welcome! You can also reach other Kepler developers and users on the Kepler Project mailing list (L). =head1 HISTORY =over 4 =item Version 1.2 [15/Mar/2006] - added optional argument to C - added function C - bug correction on C =item Version 1.1 [30/May/2005] (L) - added function C. =item Version 1.0 [21/Jan/2005] (L) =item Version 1.0 Beta [10/Nov/2004] =back =head1 VERSION This is version 1.2. =head1 CREDITS LuaFileSystem was designed by Roberto Ierusalimschy, AndrE Carregal and TomEs Guisasola as part of the Kepler Project (L), which holds its copyright. =head1 LICENSE LuaFileSystem is free software: it can be used for both academic and commercial purposes at absolutely no cost. There are no royalties or GNU-like "copyleft" restrictions. LuaFileSystem qualifies as Open Source (L) software. Its licenses are compatible with GPL (L). LuaFileSystem is not in the public domain and the Kepler Project (L) keep its copyright. The legal details are below. The spirit of the license is that you are free to use LuaFileSystem for any purpose at no cost without having to ask us. The only requirement is that if you do use LuaFileSystem, then you should give us credit by including the appropriate copyright notice somewhere in your product or its documentation. The LuaFileSystem library is designed and implemented by Roberto Ierusalimschy, AndrE Carregal and TomEs Guisasola. The implementation is not derived from licensed software. Copyright E 2004-2006 The Kepler Project. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.