pragmatic v0.1.8 Pragmatic.Windows

Utility functions for dealing with issues which arise when using Elixir on Windows.

Link to this section Summary

Functions

Return the name of the user the current process is running under. This is handy for logging errors

Take a long Windows path or a path with spaces in it and return the 8.3 version of that name

Is the currently logged-in user an admin?

Link to this section Functions

Link to this function get_current_user(list)
get_current_user([{:show_domain, boolean}]) :: String.t

Return the name of the user the current process is running under. This is handy for logging errors.

Parameters

  • show_domain: (boolean)

    • if true, return the current user in the domain\user format. Otherwise, just return user.

Examples

iex> Pragmatic.Windows.get_current_user(show_domain: false)
"caten"

iex> Pragmatic.Windows.get_current_user(show_domain: true)
"DESKTOP-3GQCDMC\\caten"
Link to this function get_short_name(path)
get_short_name(Path.t) :: Path.t

Take a long Windows path or a path with spaces in it and return the 8.3 version of that name

A runtime error will also be thrown if you attempt to run this function on a non-Windows OS. Also, the function will throw a runtime error if you attempt to invoke it on a path that doesn’t exist. Otherwise, you should specify the directory in the format drive:/dir/dir/dir etc. Contrary to the common, mistaken believe forward slashes can be used as a directory separator on Windows.

Examples

iex> Pragmatic.Windows.get_short_name("c:/nosuchpath")
** (RuntimeError) The specified directory "c:/nosuchpath" does not exist

iex> Pragmatic.Windows.get_short_name("c:/program files")
"c:/PROGRA~1"

iex> Pragmatic.Windows.get_short_name("c:/users")
"c:/Users"
Link to this function user_is_admin?()
user_is_admin?() :: boolean

Is the currently logged-in user an admin?