From 6a8efbde7620e3fc6fffe354cb01edee5d13fc93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Thu, 25 Jun 2015 13:28:14 +0200 Subject: stdlib: Add filename:basedir/2,3 --- lib/stdlib/doc/src/filename.xml | 156 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 155 insertions(+), 1 deletion(-) (limited to 'lib/stdlib/doc/src/filename.xml') diff --git a/lib/stdlib/doc/src/filename.xml b/lib/stdlib/doc/src/filename.xml index 77e262dbe6..65009753f3 100644 --- a/lib/stdlib/doc/src/filename.xml +++ b/lib/stdlib/doc/src/filename.xml @@ -47,7 +47,12 @@

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.

- + + + + + + @@ -101,6 +106,155 @@ from the result - minimizing its length.

+ + + Equivalent to basedir(Type,Application,#{}). + +

+ Equivalent to + basedir(Type, Application, #{}). +

+
+
+ + + + +

+ Returns a suitable path, or paths, for a given type. + If os is not set in Opts the function will default to + the native option, i.e. 'linux', 'darwin' or 'windows', as understood + by os:type/0. Anything not recognized as 'darwin' or 'windows' is + interpreted as 'linux'.

+

+ The options 'author' and 'version' are only used with 'windows' option mode. +

+ + user_cache +

The path location is intended for transient data files on a local machine.

+

+ On Linux: + Respects the os environment variable XDG_CACHE_HOME. +

+
+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"
+
+ user_config +

+ The path location is intended for persistent configuration files. +

+

+ On Linux: + Respects the os environment variable XDG_CONFIG_HOME. +

+
+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"
+
+ user_data +

+ The path location is intended for persistent data files. +

+

+ On Linux: + Respects the os environment variable XDG_DATA_HOME. +

+
+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"
+
+ user_log +

The path location is intended for transient log files on a local machine.

+

+ On Linux: + Respects the os environment variable XDG_CACHE_HOME.

+
+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"
+
+ site_config

+ On Linux: + Respects the os environment variable XDG_CONFIG_DIRS.

+
+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"]
+
+ site_data

+ On Linux: + Respects the os environment variable XDG_DATA_DIRS.

+
+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"]
+
+
+
+
Return the last component of a filename -- cgit v1.2.3