當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。