File: filelib.3

package info (click to toggle)
erlang-manpages 1%3A12.b.3-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,188 kB
  • ctags: 2
  • sloc: makefile: 68; perl: 30; sh: 15
file content (205 lines) | stat: -rw-r--r-- 4,581 bytes parent folder | download
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
.TH filelib 3 "stdlib  1.15.3" "Ericsson AB" "ERLANG MODULE DEFINITION"
.SH MODULE
filelib \- File utilities, such as wildcard matching of filenames
.SH DESCRIPTION
.LP
This module contains utilities on a higher level than the \fIfile\fR module\&.

.SH DATA TYPES

.nf
filename() = string() | atom() | DeepList
dirname() = filename()
DeepList = [char() | atom() | DeepList]
.fi
.SH EXPORTS
.LP
.B
ensure_dir(Name) -> ok | {error, Reason}
.br
.RS
.TP
Types
Name = filename() | dirname()
.br
Reason = posix() -- see file(3)
.br
.RE
.RS
.LP
The \fIensure_dir/1\fR function ensures that all parent directories for the given file or directory name \fIName\fR exist, trying to create them if necessary\&.
.LP
Returns \fIok\fR if all parent directories already exist or could be created, or \fI{error, Reason}\fR if some parent directory does not exist and could not be created for some reason\&.
.RE
.LP
.B
file_size(Filename) -> integer()
.br
.RS
.LP
The \fIfile_size\fR function returns the size of the given file\&.
.RE
.LP
.B
fold_files(Dir, RegExp, Recursive, Fun, AccIn) -> AccOut 
.br
.RS
.TP
Types
Dir = dirname()
.br
RegExp = regexp()
.br
Recursive = true|false
.br
Fun = fun(F, AccIn) -> AccOut
.br
AccIn = AccOut = term()
.br
.RE
.RS
.LP
The \fIfold_files/5\fR function folds the function \fIFun\fR over all (regular) files \fIF\fR in the directory \fIDir\fR that match the regular expression \fIRegExp\fR\&. If \fIRecursive\fR is true all sub-directories to \fIDir\fR are processed\&. The match is tried on just the filename without the directory part\&.
.RE
.LP
.B
is_dir(Name) -> true | false
.br
.RS
.TP
Types
Name = filename() | dirname()
.br
.RE
.RS
.LP
The \fIis_dir/1\fR function returns \fItrue\fR if \fIName\fR refers to a directory, and \fIfalse\fR otherwise\&.
.RE
.LP
.B
is_file(Name) -> true | false
.br
.RS
.TP
Types
Name = filename() | dirname()
.br
.RE
.RS
.LP
The \fIis_file/1\fR function returns \fItrue\fR if \fIName\fR refers to a file or a directory, and \fIfalse\fR otherwise\&.
.RE
.LP
.B
is_regular(Name) -> true | false
.br
.RS
.TP
Types
Name = filename()
.br
.RE
.RS
.LP
The \fIis_regular/1\fR function returns \fItrue\fR if \fIName\fR refers to a file (regular file), and \fIfalse\fR otherwise\&.
.RE
.LP
.B
last_modified(Name) -> {{Year,Month,Day},{Hour,Min,Sec}}
.br
.RS
.TP
Types
Name = filename() | dirname()
.br
.RE
.RS
.LP
The \fIlast_modified/1\fR function returns the date and time the given file or directory was last modified\&.
.RE
.LP
.B
wildcard(Wildcard) -> list()
.br
.RS
.TP
Types
Wildcard = filename() | dirname()
.br
.RE
.RS
.LP
The \fIwildcard/1\fR function returns a list of all files that match Unix-style wildcard-string \fIWildcard\fR\&.
.LP
The wildcard string looks like an ordinary filename, except that certain "wildcard characters" are interpreted in a special way\&. The following characters are special: 
.RS 2
.TP 4
.B
?:
Matches one character\&.
.TP 4
.B
*:
Matches any number of characters up to the end of the filename, the next dot, or the next slash\&.
.TP 4
.B
{Item,\&.\&.\&.}:
Alternation\&. Matches one of the alternatives\&.
.RE
.LP
Other characters represent themselves\&. Only filenames that have exactly the same character in the same position will match\&. (Matching is case-sensitive; i\&.e\&. "a" will not match "A")\&. 
.LP
Note that multiple "*" characters are allowed (as in Unix wildcards, but opposed to Windows/DOS wildcards)\&. 
.LP
Examples:
.LP
The following examples assume that the current directory is the top of an Erlang/OTP installation\&. 
.LP
To find all \fI\&.beam\fR files in all applications, the following line can be used:

.nf
    filelib:wildcard("lib/*/ebin/*\&.beam")\&.        
.fi
.LP
To find either \fI\&.erl\fR or \fI\&.hrl\fR in all applications \fIsrc\fR directories, the following

.nf
    filelib:wildcard("lib/*/src/*\&.?rl")        
.fi
.LP
or the following line

.nf
    filelib:wildcard("lib/*/src/*\&.{erl,hrl}")        
.fi
.LP
can be used\&.
.LP
To find all \fI\&.hrl\fR files in either \fIsrc\fR or \fIinclude\fR directories, use:

.nf
    filelib:wildcard("lib/*/{src,include}/*\&.hrl")\&.        
.fi
.LP
To find all \fI\&.erl\fR or \fI\&.hrl\fR files in either \fIsrc\fR or \fIinclude\fR directories, use:

.nf
    filelib:wildcard("lib/*/{src,include}/*\&.{erl,hrl}")        
.fi
.RE
.LP
.B
wildcard(Wildcard, Cwd) -> list()
.br
.RS
.TP
Types
Wildcard = filename() | dirname()
.br
Cwd = dirname()
.br
.RE
.RS
.LP
The \fIwildcard/2\fR function works like \fIwildcard/1\fR, except that instead of the actual working directory, \fICwd\fR will be used\&.
.RE