当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


erlang basedir(PathType, Application, Opts)用法及代码示例


basedir(PathType, Application, Opts) -> file:filename_all()
OTP 19.0
basedir(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

basedir_paths_type() = site_config | site_data
basedir_opts() =
#{作者=>string()|binary(),
操作系统 => 窗口 |达尔文 | linux,
版本=>string()|binary()}

返回给定类型的一个或多个合适的路径。如果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"
    在 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

    该路径位置用于持久配置文件。

    在 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"
    在 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

    该路径位置用于持久数据文件。

    在 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"
    在 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

    该路径位置适用于本地计算机上的临时日志文件。

    在 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"
    在 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

    在 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.org大神的英文原创作品 basedir(PathType, Application, Opts) -> file:filename_all()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。