basedir(PathType, Application, Opts) -> file:filename_all()
OTP 19.0basedir(PathsType, Application, Opts) -> [file:filename_all()]
OTP 19.0
类型:
PathType = basedir_path_type()
PathsType = basedir_paths_type()
Application = string() | binary()
Opts = basedir_opts()
basedir_path_type() =
user_cache | user_config | user_data | user_log
user_cache | user_config | user_data | user_log
basedir_paths_type() = site_config | site_data
返回给定类型的一个或多个合适的路径。如果Opts
中未设置os
,则该函数将默认为本机选项,即'linux'
、'darwin'
或'windows'
,如os:type/0
所理解的那样。任何未识别为 'darwin'
或 'windows'
的内容都会被解释为 'linux'
。
选项'author'
和'version'
仅与'windows'
选项模式一起使用。
-
user_cache
该路径位置适用于本地计算机上的临时数据文件。
在 Linux 上:尊重操作系统环境变量
XDG_CACHE_HOME
。1> filename:basedir(user_cache, "my_application", #{os=>linux}). "/home/otptest/.cache/my_application"
1> filename:basedir(user_cache, "my_application", #{os=>darwin}). "/home/otptest/Library/Caches/my_application"
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
该路径位置用于持久配置文件。
在 Linux 上:尊重操作系统环境变量
XDG_CONFIG_HOME
。2> filename:basedir(user_config, "my_application", #{os=>linux}). "/home/otptest/.config/my_application"
2> filename:basedir(user_config, "my_application", #{os=>darwin}). "/home/otptest/Library/Application Support/my_application"
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
该路径位置用于持久数据文件。
在 Linux 上:尊重操作系统环境变量
XDG_DATA_HOME
。3> filename:basedir(user_data, "my_application", #{os=>linux}). "/home/otptest/.local/my_application"
3> filename:basedir(user_data, "my_application", #{os=>darwin}). "/home/otptest/Library/Application Support/my_application"
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
该路径位置适用于本地计算机上的临时日志文件。
在 Linux 上:尊重操作系统环境变量
XDG_CACHE_HOME
。4> filename:basedir(user_log, "my_application", #{os=>linux}). "/home/otptest/.cache/my_application/log"
4> filename:basedir(user_log, "my_application", #{os=>darwin}). "/home/otptest/Library/Logs/my_application"
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
在 Linux 上:尊重操作系统环境变量
XDG_CONFIG_DIRS
。5> filename:basedir(site_config, "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"]
5> filename:basedir(site_config, "my_application", #{os=>darwin}). ["/Library/Application Support/my_application"]
-
site_data
在 Linux 上:尊重操作系统环境变量
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"]
5> filename:basedir(site_data, "my_application", #{os=>darwin}). ["/Library/Application Support/my_application"]
相关用法
- erlang basename(Filename)用法及代码示例
- erlang basename(Filename, Ext)用法及代码示例
- erlang binary_to_atom用法及代码示例
- erlang byte_size用法及代码示例
- erlang binary_part用法及代码示例
- erlang binary_to_float用法及代码示例
- erlang binary_to_integer用法及代码示例
- erlang binary_to_list用法及代码示例
- erlang binary_part(Subject, PosLen)用法及代码示例
- erlang binary_to_atom(Binary, Encoding)用法及代码示例
- erlang binary_to_float(Binary)用法及代码示例
- erlang binary_to_integer(Binary)用法及代码示例
- erlang binary_to_integer(Binary, Base)用法及代码示例
- erlang binary_to_term(Binary)用法及代码示例
- erlang binary_to_term(Binary, Opts)用法及代码示例
- erlang bit_size(Bitstring)用法及代码示例
- erlang bitstring_to_list(Bitstring)用法及代码示例
- erlang byte_size(Bitstring)用法及代码示例
- erlang bin_to_list(Subject, PosLen)用法及代码示例
- erlang sin用法及代码示例
- erlang cos用法及代码示例
- erlang tan用法及代码示例
- erlang asin用法及代码示例
- erlang acos用法及代码示例
- erlang atan用法及代码示例
注:本文由纯净天空筛选整理自erlang.org大神的英文原创作品 basedir(PathType, Application, Opts) -> file:filename_all()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。