WebExeBuilder Documentation

saveVariables

Category: Variable Management

Namespace: web.variables.saveVariables

Description

Saves all current variables to a file in key=value format. This makes variables persist across application restarts.

Syntax

// Save to default file
await web.variables.saveVariables();

// Save to a specific file (positional string argument)
await web.variables.saveVariables('app_variables.txt');

Parameters

  • fileName (optional) - File path to save variables (relative or absolute). If omitted, uses the default application variables file.

⚠️ Note: The argument is a positional string, not an options object. Use saveVariables('file.txt') not saveVariables({ fileName: 'file.txt' }).

Returns

Promise - Resolves with a message indicating how many variables were saved

Examples

Simple example (default file)

await web.variables.saveVariables();
console.log('Variables saved');

Save to specific path

// Save to specific location
const appDataDir = await web.directory.getAppDataDir();
const filePath = appDataDir + '\\variables.txt';

await web.variables.saveVariables(filePath);
console.log('Variables saved to:', filePath);

Auto-save on changes

// Save variables after setting them
await web.variables.setVar('lastSaved', new Date().toISOString());

// Auto-save to persist changes
await web.variables.saveVariables();
console.log('State saved');

Use Cases

  • Persist variables across application restarts
  • Create backup of application state
  • Export settings for portability
  • Auto-save user preferences
  • Implement save/restore functionality

Notes

  • File format is simple key=value pairs (one per line)
  • File includes header comments with timestamp and count
  • Automatically creates parent directories if needed
  • Uses UTF-8 encoding
  • Relative paths are resolved from application directory
  • Overwrites existing file without warning
  • Returns count of variables saved