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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
|
<HTML>
<HEAD>
<!-- refpage -->
<TITLE>filename</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<CENTER>
<A HREF="http://www.erlang.se"><IMG BORDER=0 ALT="[Erlang Systems]" SRC="min_head.gif"></A>
<H1>filename</H1>
</CENTER>
<H3>MODULE</H3>
<UL>
filename</UL>
<H3>MODULE SUMMARY</H3>
<UL>
File Name Manipulation Functions</UL>
<H3>DESCRIPTION</H3>
<UL>
<P>The module <CODE>filename</CODE> provides a number of useful
functions for analyzing and manipulating file names. These functions are
designed so that the Erlang code can work on many different platforms with different formats for file names. With file name is meant all strings that can be
used to denote a file. They can be short relative names like <CODE>foo.erl</CODE>, very long absolute name which include a drive designator and directory names like <CODE>D:\usr/local\bin\erl/lib\tools\foo.erl</CODE>, or any variations in between.<P>In Windows, all functions return file names with forward slashes
only, even if the arguments contain back slashes.
Use the <CODE>join/1</CODE> function to normalize a file name by
removing redundant directory separators.
</UL>
<H3>EXPORTS</H3>
<P><A NAME="absname%1"><STRONG><CODE>absname(Filename) -> Absname</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Filename = string() |[string()] | atom()</CODE></STRONG><BR>
<STRONG><CODE>Absname = string()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P> Converts a relative <CODE>Filename</CODE> and returns an absolute name.
No attempt is made to create the shortest
absolute name, because this can give incorrect results on
file systems which allow links.
<P> Examples include:
<PRE>Assume (for UNIX) current directory "/usr/local"
Assume (for WIN32) current directory "D:/usr/local"
(for UNIX): absname("foo") -> "/usr/local/foo"
(for WIN32): absname("foo") -> "D:/usr/local/foo"
(for UNIX): absname("../x") -> "/usr/local/../x"
(for WIN32): absname("../x") -> "D:/usr/local/../x"
(for UNIX): absname("/") -> "/"
(for WIN32): absname("/") -> "D:/"
</PRE></UL>
<P><A NAME="absname%2"><STRONG><CODE>absname(Filename, Directory) -> Absname</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Filename = string() |[string()] | atom()</CODE></STRONG><BR>
<STRONG><CODE>Directory = string()</CODE></STRONG><BR>
<STRONG><CODE>Absname = string()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P> This function works like <CODE>absname/1</CODE>, except that
the directory to which the file name should be made relative is given
explicitly in the <CODE>Directory</CODE> argument.
</UL>
<P><A NAME="basename%1"><STRONG><CODE>basename(Filename)</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Filename = string() |[string()] | atom()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P> Returns the part of the <CODE>Filename</CODE> after the
last directory separator,
or the <CODE>Filename</CODE> itself if it has no separators.
<P> Examples include:
<PRE>basename("foo") -> "foo"
basename("/usr/foo") -> "foo"
basename("/") -> []
</PRE></UL>
<P><A NAME="basename%2"><STRONG><CODE>basename(Filename,Ext) -> string()</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Filename = Ext = string() | [string()] | atom()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the last component of <CODE>Filename</CODE> with the
extension <CODE>Ext</CODE> stripped. Use this function if you want to
to remove an extension which might, or might not, be there.
Use <CODE>rootname(basename(Filename))</CODE> if you want to remove an extension
that exists, but you are not sure which one it is.
<P> Examples include:
<PRE>basename("~/src/kalle.erl", ".erl") -> "kalle"
basename("~/src/kalle.beam", ".erl") -> "kalle.beam"
basename("~/src/kalle.old.erl", ".erl") -> "kalle.old"
rootname(basename("~/src/kalle.erl")) -> "kalle"
rootname(basename("~/src/kalle.beam")) -> "kalle"
</PRE></UL>
<P><A NAME="dirname%1"><STRONG><CODE>dirname(Filename) -> string()</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Filename = string() | [string()] | atom()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the directory part of <CODE>Filename</CODE>.
<P>Examples include:
<PRE>dirname("/usr/src/kalle.erl") -> "/usr/src"
dirname("kalle.erl") -> "."
On Win32:
filename:dirname("\\usr\\src/kalle.erl") -> "/usr/src"
</PRE></UL>
<P><A NAME="extension%1"><STRONG><CODE>extension(Filename) -> string() | []</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Filename = string() | [string()] | atom()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Given a file name string <CODE>Filename</CODE>, this function returns the
file extension including the period. Returns an empty list if there is no extension.<P>Examples include:<PRE>extension("foo.erl") -> ".erl"
extension("beam.src/kalle") -> []
</PRE></UL>
<P><A NAME="join%1"><STRONG><CODE>join(Components) -> string()</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Components = [string()]</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P> Joins a list of file name <CODE>Components</CODE> with
directory separators. If one of the elements in the <CODE>Components</CODE>
list includes an absolute path, for example "/xxx", the preceding elements,
if any, are removed from the result.
<P>The result of the <CODE>join</CODE> function is "normalized":<P><UL>
<LI>There are no redundant directory separators.</LI><BR>
<LI>In Windows, all directory separators are forward slashes and the drive
letter is in lower case.</LI><BR>
</UL>
<P>Examples include:<PRE>join("/usr/local", "bin") -> "/usr/local/bin"
join(["/usr", "local", "bin"]) -> "/usr/local/bin"
join(["a/b///c/"] -> "a/b/c"
join(["B:a\\b///c/"] -> "b:a/b/c" % On Windows only
</PRE></UL>
<P><A NAME="join%2"><STRONG><CODE>join(Name1, Name2) -> string()</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Name1 = Name2 = string()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P> Joins two file name components with directory separators.
Equivalent to <CODE>join([Name1,Name2]).</CODE>
</UL>
<P><A NAME="nativename%1"><STRONG><CODE>nativename(Path) -> string()</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Path = string()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Converts a filename in <CODE>Path</CODE> to a form accepted by the command shell and native
applications on the current platform. On Windows, forward slashes
will be converted to backward slashes. On all platforms, the
name will be normalized as done by <CODE>join/1</CODE>.<P>Example:<PRE>(on UNIX) filename:nativename("/usr/local/bin/") -> "/usr/local/bin"
(on Win32) filename:nativename("/usr/local/bin/") -> "\\usr\\local\\bin"</PRE></UL>
<P><A NAME="pathtype%1"><STRONG><CODE>pathtype(Path) -> absolute | relative | volumerelative</CODE></STRONG></A><BR>
<UL>
<P>Returns one of <CODE>absolute</CODE>, <CODE>relative</CODE>, or
<CODE>volumerelative</CODE>.
<P><DL>
<DT><CODE>absolute</CODE></DT>
<DD>The path name refers to a specific file on a specific volume.
<BR>
Examples include:<BR>
<PRE>on Unix
/usr/local/bin/
on Windows
D:/usr/local/bin</PRE>
</DD>
<DT><CODE>relative</CODE></DT>
<DD> The path name is relative to the current working directory
on the current volume. <BR>
Example:<BR>
<PRE>foo/bar, ../src</PRE>
</DD>
<DT><CODE>volumerelative</CODE></DT>
<DD> The path name is relative to the current
working directory on a specified volume,
or it is a specific file on the current working volume.
<BR>
Examples include:
<BR>
<PRE>In Windows
D:bar.erl, /bar/foo.erl
/temp
</PRE>
</DD>
</DL>
</UL>
<P><A NAME="rootname%1"><STRONG><CODE>rootname(Filename) -> string()</CODE></STRONG></A><BR>
<A NAME="rootname%2"><STRONG><CODE>rootname(Filename, Ext) -> string()</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Filename = Ext = string() | [string()] | atom()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P> <CODE>rootname/1</CODE> returns all characters in <CODE>Filename</CODE>,
except the extension.
<P> <CODE>rootname/2</CODE> works as <CODE>rootname/1</CODE>, except that the
extension is removed only if it is <CODE>Ext</CODE>.
<P>Examples include:
<PRE>rootname("/beam.src/kalle") -> "/beam.src/kalle"
rootname("/beam.src/foo.erl") -> "/beam.src/foo"
rootname("/beam.src/foo.erl",".erl") -> "/beam.src/foo"
rootname("/beam.src/foo.beam",".erl") -> "/beam.src/foo.beam"
</PRE></UL>
<P><A NAME="split%1"><STRONG><CODE>split(Filename) -> Components</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Filename = string() | [string()] | atom()</CODE></STRONG><BR>
<STRONG><CODE>Components = [string()]</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns a list whose elements are the path components of <CODE>Filename</CODE>.
<P>Examples include:
<PRE>split("/usr/local/bin") -> ["/", "usr", "local", "bin"]
split("foo/bar") -> ["foo", "bar"]
split("a:\\msdev\\include") -> ["a:/", "msdev", "include"]
</PRE></UL>
<P><A NAME="find_src%1"><STRONG><CODE>find_src(Module) -> {SourceFile, Options}</CODE></STRONG></A><BR>
<A NAME="find_src%2"><STRONG><CODE>find_src(Module, Rules) -> {SourceFile, Options}</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Module = atom() | string()</CODE></STRONG><BR>
<STRONG><CODE>SourceFile = string()</CODE></STRONG><BR>
<STRONG><CODE>Options = [CompilerOption]</CODE></STRONG><BR>
<STRONG><CODE>CompilerOption = {i, string()} | {outdir, string()} | {d, atom()}</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P> Finds the source file name and compilation options for a compiled
module. The result can be fed to <CODE>compile:file/2</CODE> in order to compile the
file again.
<P> The Module argument, which can be a string or an atom, specifies
either the module name or the path to the source code, with or
without the ".erl" extension. In either case, the module must be
known by the code manager, i.e. <CODE>code:which/1</CODE> must succeed.
<P> Rules describe how the source directory is found, when
the object code directory is known. Each rule is of the form
<CODE>{BinSuffix, SourceSuffix}</CODE> and is interpreted as follows:
If the end of the directory name where the object is located matches
<CODE>BinSuffix</CODE>, then the suffix of the directory name is replaced by
<CODE>SourceSuffix</CODE>.
If the source file is found in the resulting
directory, then the function returns that location together with
<CODE>Options</CODE>. Otherwise, the next rule is tried, and so on.
<P> The function returns <CODE>{SourceFile, Options}</CODE>.
<CODE>SourceFile</CODE> is the absolute path to the source file
without the ".erl" extension. <CODE>Options</CODE>
include the options which are necessary to compile the file
with <CODE>compile:file/2</CODE>, but excludes options
such as <CODE>report</CODE> or <CODE>verbose</CODE> which do not change
the way code is generated.
The paths in the <CODE>{outdir, Path}</CODE> and <CODE>{i, Path}</CODE>
options are guaranteed to be absolute.
</UL>
<H3>AUTHORS</H3>
<UL>
Björn Gustavsson - support@erlang.ericsson.se<BR>
</UL>
<CENTER>
<HR>
<FONT SIZE=-1>stdlib 1.10<BR>
Copyright © 1991-2001
<A HREF="http://www.erlang.se">Ericsson Utvecklings AB</A><BR>
<!--#include virtual="/ssi/otp_footer.html"-->
</FONT>
</CENTER>
</BODY>
</HTML>
|