The module
In Windows, all functions return file names with forward slashes
only, even if the arguments contain back slashes. Use
name() = string() | atom() | DeepList
DeepList = [char() | atom() | DeepList]
Converts a relative
Unix examples:
1> pwd(). "/usr/local" 2> filename:absname("foo"). "/usr/local/foo" 3> filename:absname("../x"). "/usr/local/../x" 4> filename:absname("/"). "/"
Windows examples:
1> pwd(). "D:/usr/local" 2> filename:absname("foo"). "D:/usr/local/foo" 3> filename:absname("../x"). "D:/usr/local/../x" 4> filename:absname("/"). "D:/"
This function works like
Joins an absolute directory with a relative filename.
Similar to
Returns the last component of
5> filename:basename("foo"). "foo" 6> filename:basename("/usr/foo"). "foo" 7> filename:basename("/"). []
Returns the last component of
8> filename:basename("~/src/kalle.erl", ".erl"). "kalle" 9> filename:basename("~/src/kalle.beam", ".erl"). "kalle.beam" 10> filename:basename("~/src/kalle.old.erl", ".erl"). "kalle.old" 11> filename:rootname(filename:basename("~/src/kalle.erl")). "kalle" 12> filename:rootname(filename:basename("~/src/kalle.beam")). "kalle"
Returns the directory part of
13> filename:dirname("/usr/src/kalle.erl"). "/usr/src" 14> filename:dirname("kalle.erl"). "." 5> filename:dirname("\\\\usr\\\\src/kalle.erl"). % Windows "/usr/src"
Returns the file extension of
15> filename:extension("foo.erl"). ".erl" 16> filename:extension("beam.src/kalle"). []
Converts a possibly deep list filename consisting of characters and atoms into the corresponding flat string filename.
Joins a list of file name
The result is "normalized":
17> filename:join(["/usr", "local", "bin"]). "/usr/local/bin" 18> filename:join(["a/b///c/"]). "a/b/c" 6> filename:join(["B:a\\\\b///c/"]). % Windows "b:a/b/c"
Joins two file name components with directory separators.
Equivalent to
Converts
19> filename:nativename("/usr/local/bin/"). % Unix "/usr/local/bin" 7> filename:nativename("/usr/local/bin/"). % Windows "\\\\usr\\\\local\\\\bin"
Returns the type of path, one of
The path name refers to a specific file on a specific volume.
Unix example:
Windows example:
The path name is relative to the current working directory on the current volume.
Example:
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.
Windows example:
Remove a filename extension.
20> filename:rootname("/beam.src/kalle"). /beam.src/kalle" 21> filename:rootname("/beam.src/foo.erl"). "/beam.src/foo" 22> filename:rootname("/beam.src/foo.erl", ".erl"). "/beam.src/foo" 23> filename:rootname("/beam.src/foo.beam", ".erl"). "/beam.src/foo.beam"
Returns a list whose elements are the path components of
24> filename:split("/usr/local/bin"). ["/","usr","local","bin"] 25> filename:split("foo/bar"). ["foo","bar"] 26> filename:split("a:\\\\msdev\\\\include"). ["a:/","msdev","include"]
Finds the source filename and compiler options for a module.
The result can be fed to
The
[{"", ""}, {"ebin", "src"}, {"ebin", "esrc"}]
If the source file is found in the resulting directory, then
the function returns that location together with
The function returns