filename

MODULE

filename

MODULE SUMMARY

Filename Manipulation Functions

DESCRIPTION

The module filename 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 foo.erl, very long absolute
name which include a drive designator and directory names like
D:\usr/local\bin\erl/lib\tools\foo.erl, or any variations
in between.

In Windows, all functions return file names with forward slashes
only, even if the arguments contain back slashes. Use
join/1 to normalize a file name by removing redundant
directory separators.

The module supports raw file names in the way that if a binary is present, or the file name cannot be interpreted according to the return value of
file:native_name_encoding/0, a raw file name will also be returned. For example filename:join/1 provided with a path component being a binary (and also not being possible to interpret under the current native file name encoding) will result in a raw file name being returned (the join operation will have been performed of course). For more information about raw file names, see the file module.

Joins an absolute directory with a relative filename.
Similar to join/2, but on platforms with tight
restrictions on raw filename length and no support for
symbolic links (read: VxWorks), leading parent directory
components in Filename are matched against trailing
directory components in Dir so they can be removed
from the result - minimizing its length.

Returns the last component of Filename with the
extension Ext stripped. This function should be used
to remove a specific extension which might, or might not, be
there. Use rootname(basename(Filename)) to remove an
extension that exists, but you are not sure which one it is.

Joins a list of file name Components with directory
separators. If one of the elements of Components
includes an absolute path, for example "/xxx",
the preceding elements, if any, are removed from the result.

The result is "normalized":

Redundant directory separators are removed.

In Windows, all directory separators are forward
slashes and the drive letter is in lower case.

Converts Path to a form accepted by the command shell
and native applications on the current platform. On Windows,
forward slashes is converted to backward slashes. On all
platforms, the name is normalized as done by join/1.

Finds the source filename and compiler options for a module.
The result can be fed to compile:file/2 in order to
compile the file again.

Warning

We don't recommend using this function. If possible,
use beam_lib(3) to extract
the abstract code format from the BEAM file and compile that
instead.

The Beam 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 server, i.e.
code:which(Module) must succeed.

Rules describes how the source directory can be found,
when the object code directory is known. It is a list of
tuples {BinSuffix, SourceSuffix} and is interpreted
as follows: If the end of the directory name where the object
is located matches BinSuffix, then the source code
directory has the same name, but with BinSuffix
replaced by SourceSuffix. Rules defaults to:

[{"", ""}, {"ebin", "src"}, {"ebin", "esrc"}]

If the source file is found in the resulting directory, then
the function returns that location together with
Options. Otherwise, the next rule is tried, and so on.

The function returns {SourceFile, Options} if it succeeds.
SourceFile is the absolute path to the source file
without the ".erl" extension. Options include
the options which are necessary to recompile the file with
compile:file/2, but excludes options such as
report or verbose which do not change the way
code is generated. The paths in the {outdir, Path}
and {i, Path} options are guaranteed to be
absolute.