~rdoering/ubuntu/karmic/erlang/fix-535090

« back to all changes in this revision

Viewing changes to lib/stdlib/doc/src/filelib.xml

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090215164252-q5x4rcf8a5pbesb1
Tags: 1:12.b.5-dfsg-2
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="latin1" ?>
 
2
<!DOCTYPE erlref SYSTEM "erlref.dtd">
 
3
 
 
4
<erlref>
 
5
  <header>
 
6
    <copyright>
 
7
      <year>2003</year>
 
8
      <year>2007</year>
 
9
      <holder>Ericsson AB, All Rights Reserved</holder>
 
10
    </copyright>
 
11
    <legalnotice>
 
12
  The contents of this file are subject to the Erlang Public License,
 
13
  Version 1.1, (the "License"); you may not use this file except in
 
14
  compliance with the License. You should have received a copy of the
 
15
  Erlang Public License along with this software. If not, it can be
 
16
  retrieved online at http://www.erlang.org/.
 
17
 
 
18
  Software distributed under the License is distributed on an "AS IS"
 
19
  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
20
  the License for the specific language governing rights and limitations
 
21
  under the License.
 
22
 
 
23
  The Initial Developer of the Original Code is Ericsson AB.
 
24
    </legalnotice>
 
25
 
 
26
    <title>filelib</title>
 
27
    <prepared>Bjorn Gustavsson</prepared>
 
28
    <responsible>Bjorn Gustavsson</responsible>
 
29
    <docno>1</docno>
 
30
    <approved>Kenneth Lundin</approved>
 
31
    <checked></checked>
 
32
    <date>03-01-21</date>
 
33
    <rev>A</rev>
 
34
    <file>filelib.sgml</file>
 
35
  </header>
 
36
  <module>filelib</module>
 
37
  <modulesummary>File utilities, such as wildcard matching of filenames</modulesummary>
 
38
  <description>
 
39
    <p>This module contains utilities on a higher level than the <c>file</c>
 
40
      module.</p>
 
41
  </description>
 
42
 
 
43
  <section>
 
44
    <title>DATA TYPES</title>
 
45
    <code type="none">
 
46
filename() = string() | atom() | DeepList
 
47
dirname() = filename()
 
48
DeepList = [char() | atom() | DeepList]</code>
 
49
  </section>
 
50
 
 
51
  <funcs>
 
52
    <func>
 
53
      <name>ensure_dir(Name) -> ok | {error, Reason}</name>
 
54
      <fsummary>Ensure that all parent directories for a file or directory exist.</fsummary>
 
55
      <type>
 
56
        <v>Name = filename() | dirname()</v>
 
57
        <v>Reason = posix() -- see file(3)</v>
 
58
      </type>
 
59
      <desc>
 
60
        <p>The <c>ensure_dir/1</c> function ensures that all parent
 
61
          directories for the given file or directory name <c>Name</c>
 
62
          exist, trying to create them if necessary.</p>
 
63
        <p>Returns <c>ok</c> if all parent directories already exist
 
64
          or could be created, or <c>{error, Reason}</c> if some parent
 
65
          directory does not exist and could not be created for some
 
66
          reason.</p>
 
67
      </desc>
 
68
    </func>
 
69
    <func>
 
70
      <name>file_size(Filename) -> integer()</name>
 
71
      <fsummary>Return the size in bytes of the file.</fsummary>
 
72
      <desc>
 
73
        <p>The <c>file_size</c> function returns the size of the given file.</p>
 
74
      </desc>
 
75
    </func>
 
76
    <func>
 
77
      <name>fold_files(Dir, RegExp, Recursive, Fun, AccIn) -> AccOut   </name>
 
78
      <fsummary>Fold over all files matching a regular expression.</fsummary>
 
79
      <type>
 
80
        <v>Dir = dirname()</v>
 
81
        <v>RegExp = regexp()</v>
 
82
        <v>Recursive = true|false</v>
 
83
        <v>Fun = fun(F, AccIn) -> AccOut</v>
 
84
        <v>AccIn = AccOut = term()</v>
 
85
      </type>
 
86
      <desc>
 
87
        <p>The <c>fold_files/5</c> function folds the function
 
88
          <c>Fun</c> over all (regular) files <c>F</c> in the
 
89
          directory <c>Dir</c> that match the regular expression <c>RegExp</c>.
 
90
          If <c>Recursive</c> is true all sub-directories to <c>Dir</c>
 
91
          are processed. The match is tried on just the filename without
 
92
          the directory part.</p>
 
93
      </desc>
 
94
    </func>
 
95
    <func>
 
96
      <name>is_dir(Name) -> true | false</name>
 
97
      <fsummary>Test whether Name refer to a directory or not</fsummary>
 
98
      <type>
 
99
        <v>Name = filename() | dirname()</v>
 
100
      </type>
 
101
      <desc>
 
102
        <p>The <c>is_dir/1</c> function returns <c>true</c> if <c>Name</c>
 
103
          refers to a directory, and <c>false</c> otherwise.</p>
 
104
      </desc>
 
105
    </func>
 
106
    <func>
 
107
      <name>is_file(Name) -> true | false</name>
 
108
      <fsummary>Test whether Name refer to a file or directory.</fsummary>
 
109
      <type>
 
110
        <v>Name = filename() | dirname()</v>
 
111
      </type>
 
112
      <desc>
 
113
        <p>The <c>is_file/1</c> function returns <c>true</c> if <c>Name</c>
 
114
          refers to a file or a directory, and <c>false</c> otherwise.</p>
 
115
      </desc>
 
116
    </func>
 
117
    <func>
 
118
      <name>is_regular(Name) -> true | false</name>
 
119
      <fsummary>Test whether Name refer to a (regular) file.</fsummary>
 
120
      <type>
 
121
        <v>Name = filename()</v>
 
122
      </type>
 
123
      <desc>
 
124
        <p>The <c>is_regular/1</c> function returns <c>true</c> if <c>Name</c>
 
125
          refers to a file (regular file), and <c>false</c> otherwise.</p>
 
126
      </desc>
 
127
    </func>
 
128
    <func>
 
129
      <name>last_modified(Name) -> {{Year,Month,Day},{Hour,Min,Sec}} | 0</name>
 
130
      <fsummary>Return the local date and time when a file was last modified.</fsummary>
 
131
      <type>
 
132
        <v>Name = filename() | dirname()</v>
 
133
      </type>
 
134
      <desc>
 
135
        <p>The <c>last_modified/1</c> function returns the date and time the
 
136
          given file or directory was last modified, or 0 if the file
 
137
          does not exist.</p>
 
138
      </desc>
 
139
    </func>
 
140
    <func>
 
141
      <name>wildcard(Wildcard) -> list()</name>
 
142
      <fsummary>Match filenames using Unix-style wildcards.</fsummary>
 
143
      <type>
 
144
        <v>Wildcard = filename() | dirname()</v>
 
145
      </type>
 
146
      <desc>
 
147
        <p>The <c>wildcard/1</c> function returns a list of all files
 
148
          that match Unix-style wildcard-string <c>Wildcard</c>.</p>
 
149
        <p>The wildcard string looks like an ordinary filename, except
 
150
          that certain "wildcard characters" are interpreted in a special
 
151
          way. The following characters are special:
 
152
          </p>
 
153
        <taglist>
 
154
          <tag>?</tag>
 
155
          <item>
 
156
            <p>Matches one character.</p>
 
157
          </item>
 
158
          <tag>*</tag>
 
159
          <item>
 
160
            <p>Matches any number of characters up to the end of
 
161
              the filename, the next dot, or the next slash.</p>
 
162
          </item>
 
163
          <tag>{Item,...}</tag>
 
164
          <item>
 
165
            <p>Alternation. Matches one of the alternatives.</p>
 
166
          </item>
 
167
        </taglist>
 
168
        <p>Other characters represent themselves. Only filenames that
 
169
          have exactly the same character in the same position will match.
 
170
          (Matching is case-sensitive; i.e. "a" will not match "A").
 
171
          </p>
 
172
        <p>Note that multiple "*" characters are allowed
 
173
          (as in Unix wildcards, but opposed to Windows/DOS wildcards).
 
174
          </p>
 
175
        <p>Examples:</p>
 
176
        <p>The following examples assume that the current directory is the
 
177
          top of an Erlang/OTP installation.
 
178
          </p>
 
179
        <p>To find all <c>.beam</c> files in all applications, the following
 
180
          line can be used:</p>
 
181
        <code type="none">
 
182
    filelib:wildcard("lib/*/ebin/*.beam").        </code>
 
183
        <p>To find either <c>.erl</c> or <c>.hrl</c> in all applications
 
184
          <c>src</c> directories, the following</p>
 
185
        <code type="none">
 
186
    filelib:wildcard("lib/*/src/*.?rl")        </code>
 
187
        <p>or the following line</p>
 
188
        <code type="none">
 
189
    filelib:wildcard("lib/*/src/*.{erl,hrl}")        </code>
 
190
        <p>can be used.</p>
 
191
        <p>To find all <c>.hrl</c> files in either <c>src</c> or <c>include</c>
 
192
          directories, use:</p>
 
193
        <code type="none">
 
194
    filelib:wildcard("lib/*/{src,include}/*.hrl").        </code>
 
195
        <p>To find all <c>.erl</c> or <c>.hrl</c> files in either
 
196
          <c>src</c> or <c>include</c> directories, use:</p>
 
197
        <code type="none">
 
198
    filelib:wildcard("lib/*/{src,include}/*.{erl,hrl}")        </code>
 
199
      </desc>
 
200
    </func>
 
201
    <func>
 
202
      <name>wildcard(Wildcard, Cwd) -> list()</name>
 
203
      <fsummary>Match filenames using Unix-style wildcards starting at a specified directory.</fsummary>
 
204
      <type>
 
205
        <v>Wildcard = filename() | dirname()</v>
 
206
        <v>Cwd = dirname()</v>
 
207
      </type>
 
208
      <desc>
 
209
        <p>The <c>wildcard/2</c> function works like <c>wildcard/1</c>,
 
210
          except that instead of the actual working directory, <c>Cwd</c>
 
211
          will be used.</p>
 
212
      </desc>
 
213
    </func>
 
214
  </funcs>
 
215
</erlref>
 
216
 
 
217