beetlebug▾
/

ztcl::appdatafile

Gives the data folder of an app for the user, with no env capability.

ztcl::appdata NAME

Description

Gives the data folder of the app NAME for the user: the folder where a program keeps the data of that user. It gives the path and makes no folder. A program makes the folder with file mkdir when it needs it.

The command is not a package: it exists when the embedder turns on the capability file, as file home does, and the ztcl program turns it on with --allow file. It needs no env capability: it reads the variables of the process itself, and it does not make the array env visible.

With a root folder (--root DIR, or fsroot.setRoot in Zig), the folder is /.local/share/NAME inside the root, the same on each system, and file home gives / there. In host mode (fsroot.setHost in Zig, or no --root in the ztcl program), the folder follows the system: $XDG_DATA_HOME/NAME, or $HOME/.local/share/NAME when XDG_DATA_HOME is empty or absent, on Linux; $HOME/Library/Application Support/NAME on macOS; and %APPDATA%\NAME, or $HOME\AppData\Roaming\NAME when APPDATA is empty or absent, on Windows. An empty variable counts as absent. With no HOME (and no APPDATA on Windows), the command gives TCL VALUE PATH HOMELESS, as file home does.

NAME is one path element: it is not empty, has no / and no \, and is not . or ... Another name gives TCL VALUE PATH NAME. The examples of this page run in an empty root folder with --root . --allow file,channels.

Arguments

ArgumentTypeDefaultDescription
NAMEstringrequiredThe name of the app, one path element.

Returns

The path of the data folder of the app.

Examples

% ztcl::appdata cardbox
/.local/share/cardbox

% list [ztcl::appdata cardbox] [file exists /.local/share/cardbox]
/.local/share/cardbox 0

Errors

% ztcl::appdata
wrong # args: should be "ztcl::appdata name"
-errorcode TCL WRONGARGS

% ztcl::appdata a b
wrong # args: should be "ztcl::appdata name"
-errorcode TCL WRONGARGS

% ztcl::appdata {}
bad name "": must be one path element
-errorcode TCL VALUE PATH NAME

% ztcl::appdata .
bad name ".": must be one path element
-errorcode TCL VALUE PATH NAME

% ztcl::appdata ..
bad name "..": must be one path element
-errorcode TCL VALUE PATH NAME

% ztcl::appdata a/b
bad name "a/b": must be one path element
-errorcode TCL VALUE PATH NAME

% ztcl::appdata {a\b}
bad name "a\b": must be one path element
-errorcode TCL VALUE PATH NAME

Facts

Capability
file. A new interpreter does not have it until the host turns it on.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.10

The full page: ztcl::appdata.

See also