The module
In Windows, all functions return file names with forward slashes
only, even if the arguments contain back slashes. Use
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
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
Equivalent to
Returns a suitable path, or paths, for a given type.
If
The options
The path location is intended for transient data files on a local machine.
On Linux:
Respects the os environment variable
1> filename:basedir(user_cache, "my_application", #{os=>linux}). "/home/otptest/.cache/my_application"On Darwin:
1> filename:basedir(user_cache, "my_application", #{os=>darwin}). "/home/otptest/Library/Caches/my_application"On Windows:
1> filename:basedir(user_cache, "My App"). "c:/Users/otptest/AppData/Local/My App/Cache" 2> filename:basedir(user_cache, "My App"). "c:/Users/otptest/AppData/Local/My App/Cache" 3> filename:basedir(user_cache, "My App", #{author=>"Erlang"}). "c:/Users/otptest/AppData/Local/Erlang/My App/Cache" 4> filename:basedir(user_cache, "My App", #{version=>"1.2"}). "c:/Users/otptest/AppData/Local/My App/1.2/Cache" 5> filename:basedir(user_cache, "My App", #{author=>"Erlang",version=>"1.2"}). "c:/Users/otptest/AppData/Local/Erlang/My App/1.2/Cache"
The path location is intended for persistent configuration files.
On Linux:
Respects the os environment variable
2> filename:basedir(user_config, "my_application", #{os=>linux}). "/home/otptest/.config/my_application"On Darwin:
2> filename:basedir(user_config, "my_application", #{os=>darwin}). "/home/otptest/Library/Application Support/my_application"On Windows:
1> filename:basedir(user_config, "My App"). "c:/Users/otptest/AppData/Roaming/My App" 2> filename:basedir(user_config, "My App", #{author=>"Erlang", version=>"1.2"}). "c:/Users/otptest/AppData/Roaming/Erlang/My App/1.2"
The path location is intended for persistent data files.
On Linux:
Respects the os environment variable
3> filename:basedir(user_data, "my_application", #{os=>linux}). "/home/otptest/.local/my_application"On Darwin:
3> filename:basedir(user_data, "my_application", #{os=>darwin}). "/home/otptest/Library/Application Support/my_application"On Windows:
8> filename:basedir(user_data, "My App"). "c:/Users/otptest/AppData/Local/My App" 9> filename:basedir(user_data, "My App",#{author=>"Erlang",version=>"1.2"}). "c:/Users/otptest/AppData/Local/Erlang/My App/1.2"
The path location is intended for transient log files on a local machine.
On Linux:
Respects the os environment variable
4> filename:basedir(user_log, "my_application", #{os=>linux}). "/home/otptest/.cache/my_application/log"On Darwin:
4> filename:basedir(user_log, "my_application", #{os=>darwin}). "/home/otptest/Library/Caches/my_application"On Windows:
12> filename:basedir(user_log, "My App"). "c:/Users/otptest/AppData/Local/My App/Logs" 13> filename:basedir(user_log, "My App",#{author=>"Erlang",version=>"1.2"}). "c:/Users/otptest/AppData/Local/Erlang/My App/1.2/Logs"
On Linux:
Respects the os environment variable
5> filename:basedir(site_data, "my_application", #{os=>linux}). ["/usr/local/share/my_application", "/usr/share/my_application"] 6> os:getenv("XDG_CONFIG_DIRS"). "/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg" 7> filename:basedir(site_config, "my_application", #{os=>linux}). ["/etc/xdg/xdg-ubuntu/my_application", "/usr/share/upstart/xdg/my_application", "/etc/xdg/my_application"] 8> os:unsetenv("XDG_CONFIG_DIRS"). true 9> filename:basedir(site_config, "my_application", #{os=>linux}). ["/etc/xdg/my_application"]On Darwin:
5> filename:basedir(site_config, "my_application", #{os=>darwin}). ["/Library/Application Support/my_application"]
On Linux:
Respects the os environment variable
10> os:getenv("XDG_DATA_DIRS"). "/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/" 11> filename:basedir(site_data, "my_application", #{os=>linux}). ["/usr/share/ubuntu/my_application", "/usr/share/gnome/my_application", "/usr/local/share/my_application", "/usr/share/my_application"] 12> os:unsetenv("XDG_DATA_DIRS"). true 13> filename:basedir(site_data, "my_application", #{os=>linux}). ["/usr/local/share/my_application", "/usr/share/my_application"]On Darwin:
5> filename:basedir(site_data, "my_application", #{os=>darwin}). ["/Library/Application Support/my_application"]
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
We don't recommend using this function. If possible,
use
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