aboutsummaryrefslogtreecommitdiff
path: root/doc/us/manual.html
blob: 26a21920100ee45c1036a3b40937cdffe1a27b02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<title>LuaFileSystem</title>
<style type="text/css">
ul { list-style-type: disc };
</style>
</head>
<body bgcolor="#FFFFFF">
<hr>
<center>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td align="center"><a href=
"http://www.keplerproject.org/luafilesystem"><img border="0" alt=
"LuaFileSystem logo" src="luafilesystem.png"></a> </td>
</tr>

<tr>
<td align="center"><big><b>LuaFileSystem Reference Manual</b></big>
</td>
</tr>

<tr>
<td align="center" valign="top">File system library for the <a
href="http://www.lua.org">Lua</a> programming language</td>
</tr>
</table>
</center>

<center><small><a href="index.html">home</a> &middot; <a href=
"#introduction">introduction</a> &middot; <a href=
"#reference">reference</a> &middot; <a href=
"#example">example</a></small></center>

<hr>
<a name="introduction"></a> 

<h2>Introduction</h2>

<p>LuaFileSystem is a <a href="http://www.lua.org">Lua</a> library
developed to complement the set of functions related to file
systems offered by the standard Lua distribution.</p>

<p>LuaFileSystem is free software and uses the same <a href=
"license.html">license</a> as Lua 5.0.</p>

<a name="reference"></a> 

<h2>Reference</h2>

<p>LuaFileSystem offers the following functions:</p>

<ul>
<a name="attributes"></a>
<li><b><tt>lfs.attributes (filepath)</tt></b><br>
 Obtains the file attributes. The attributes are: 

<div style="margin-left: 2em"><i>dev</i>, device inode resides
on;<br>
 <i>ino</i>, inode's number;<br>
 <i>mode</i>, inode protection mode (<small>values could be
<tt>file</tt>, <tt>directory</tt>, <tt>link</tt>, <tt>socket</tt>,
<tt>named pipe</tt>, <tt>char device</tt>, <tt>block device</tt> or
<tt>other</tt></small>);<br>
 <i>nlink</i>, number of hard links to the file;<br>
 <i>uid</i>, user-id of owner;<br>
 <i>gid</i>, group-id of owner;<br>
 <i>rdev</i>, device type, for special file inode;<br>
 <i>access</i>, time of last access;<br>
 <i>modification</i>, time of last data modification;<br>
 <i>change</i>, time of last file status change;<br>
 <i>size</i>, file size, in bytes;<br>
 <i>blocks</i>, block allocated for file; (Unix only)<br>
 <i>blksize</i>, optimal file system I/O blocksize; (Unix only)<br>
</div>

Returns a table with file attributes described above.
</li>

<a name="chdir"></a>
<li><b><tt>lfs.chdir (path)</tt></b><br>
 Changes the current working directory to the given
<tt>path</tt>.<br>
 Returns <tt>true</tt> in case of success or <tt>nil</tt> plus an
error string.
</li>

<a name="getcwd"></a>
<li><b><tt>lfs.currentdir ()</tt></b><br>
 Returns a string with the current working directory or
<code>nil</code> plus an error string.
</li>

<a name="dir"></a>
<li><b><tt>lfs.dir (path)</tt></b><br>
 Lua iterator over the entries of a given directory. Raises an
error if <tt>path</tt> is not a directory.
</li>

<a name="lock"></a>
<li><b><tt>lfs.lock (filehandle, mode[, start[, length]])</tt></b><br>
 Locks a file or a part of it. This function works on <em>open
files</em>; the file handle should be specified as the first
argument. The string <code>mode</code> could be either
<code>r</code> (for a read/shared lock) or <code>w</code> (for a
write/exclusive lock). The optional arguments <code>start</code>
and <code>length</code> can be used to specify a starting point and
its length; both should be numbers.<br>
 Returns a boolean indicating if the operation was successful; in
case of error, it returns <code>false</code> plus an error string.
</li>

<a name="mkdir"></a>
<li><b><tt>lfs.mkdir (dirname)</tt></b><br>
 Creates a new directory. The argument is the name of the new
directory.<br>
 Returns a boolean indicating whether the operation succeeds or not
(in this case, an error string is returned too).
</li>

<a name="touch"></a>
<li><b><tt>lfs.touch (filepath [, atime [, mtime]])</tt></b><br>
Set access and modification times of a file.
This function is a bind to <tt>utime</tt> function.
The first argument is the filename,
the second argument is the access time,
and the third argument is the modification time.
Both times are provided in seconds (which should be generated with
Lua standard function <tt>os.date</tt>).
If the modifition time is omitted, the access time provided is used;
if both times are omitted, the current time is used.<br>
Returns a boolean indicating whethet the operation succeeds or not
(followed by an error string in case it fails).
</li>

<a name="unlock"></a>
<li><b><tt>lfs.unlock (filehandle[, start[, length]])</tt></b><br>
 Unlocks a file or a part of it. This function works on <em>open
files</em>; the file handle should be specified as the first
argument. The optional arguments <code>start</code> and
<code>length</code> can be used to specify a starting point and its
length; both should be numbers.<br>
 Returns a boolean indicating if the operation was successful; in
case of error, it returns <code>false</code> plus a string
describing the error.</li>
</ul>

<a name="example"></a> 
<h2>Example</h2>

<pre>
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 (".")
</pre>

<a name="contents"></a> 

<h2>Contents</h2>

<ul>
<li><a href="#introduction">Introduction</a></li>

<li><a href="#reference">Reference</a> 

<ul>
<li><a href="#chdir">chdir</a></li>

<li><a href="#currentdir">currentdir</a></li>

<li><a href="#dir">dir</a></li>

<li><a href="#lock">lock</a></li>

<li><a href="#mkdir">mkdir</a></li>

<li><a href="#unlock">unlock</a></li>
</ul>
</li>

<li><a href="#examples">Examples</a></li>
</ul>

<br>
<br>
 

<center><small><a href="index.html">home</a> &middot; <a href=
"#introduction">introduction</a> &middot; <a href=
"#reference">reference</a> &middot; <a href=
"#example">example</a></small></center>

<hr>
<small>$Id: manual.html,v 1.7 2004/11/10 14:09:45 tuler Exp
$</small>
</body>
</html>