aboutsummaryrefslogtreecommitdiff
path: root/doc/us/manual.html
blob: 5ca685d77ee3e90b20108d1df55325a7b48ebb44 (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
<! See Copyright Notice in license.html>
<html>

<head>
<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>
<tr><td align=center><big><b>LuaFileSystem Reference Manual</b></big>
<tr><td align=center valign=top>File system library for the 
<a href="http://www.lua.org">Lua</a>
programming language
</table>
</center>
<p>

<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>
<p>

<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>
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:
<ul>
  <a name="attributes"></a>
  <li> <b><tt>lfs.attributes (filepath)</tt></b> <br>
    Returns a table with file attributes.

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

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

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

  <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.
    Returns a boolean indicating if the operation was successful;
    in case of error, it returns <code>false</code> plus an error string.

  <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.
    Returns a boolean indicating whether the operation succeeds or not.

  <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.
    This function returns a boolean indicating if the operation was successful;
    in case of error, it returns <code>false</code> plus a string describing the
    error.

</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>
<p>
<ul>
  <li> <a href="#introduction">Introduction</a>
  <li> <a href="#reference">Reference</a>
    <ul>
      <li> <a href="#chdir">chdir</a>
      <li> <a href="#currentdir">currentdir</a>
      <li> <a href="#dir">dir</a>
      <li> <a href="#lock">lock</a>
      <li> <a href="#mkdir">mkdir</a>
      <li> <a href="#unlock">unlock</a>
    </ul>
  <li> <a href="#examples">Examples</a>
</ul>
</p>


<p>
<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>
<p>

<hr>
<small>
$Id: manual.html,v 1.5 2004/11/01 15:27:13 tomas Exp $
</small>

</body>
</html>