rb.file reads and writes files in the script’s directory and in its data
folder. A script reaches for it to keep settings, state, logs, and recordings
between runs.
This script counts its runs in a JSON file in its data folder and appends a
line to a log beside it:
Absolute paths are not allowed; a path containing .. or one that leaves
the directory raises Path traversal detected.
A path starting with @data/, or @data alone, reaches the script’s data
folder instead; it needs min_sdk=3.13.0. There is one data folder for each
package or standalone script, kept outside the scripts folder under
script-data in Rebind’s data folder, and created when first used. The same
path rules apply inside it. rebind script data <path> prints where it is.
A marketplace update, a move, or a rename keeps the data folder. A new script, a
copy, a script moved into or out of a package, and an install that replaces a
same-named file or package Rebind cannot verify as the same source start with an
empty folder; data left behind by a replaced install is moved to
script-data/.displaced, not deleted. Deleting the script or package in Rebind
deletes its data folder. Cloud backups, the scripts folder, and shared
packages leave it out, so it suits recordings, logs, and other data a script
collects.
rb.file.rmdir("@data") raises, though what is inside can be removed. A script
with no file, such as a scratchpad, has no data folder: @data paths raise,
and exists, is_dir, and is_file return false. Sound files for
rb.audio.play, needles for rb.screen.find_image, and rb.config paths
accept @data/ paths too.
Other failures raise the operating system’s message.