| name | bx-ini |
| description | Use this skill when reading or writing INI configuration files in BoxLang with the bx-ini module: getIniFile(), getProfileString(), setProfileString(), getProfileSections(), removeProfileSection(), and fluent IniFile object methods. |
bx-ini: INI File Handling
Installation
install-bx-module bx-ini
box install bx-ini
BIFs
| BIF | Description |
|---|
getIniFile( file ) | Open (or create) an INI file, returns an IniFile object |
getProfileString( iniFile, section, entry ) | Get a single entry value |
setProfileString( iniFile, section, entry, value ) | Set a single entry value |
getProfileSection( iniFile, section ) | Get an entire section as a struct |
getProfileSections( iniFile ) | Get all sections as a struct of structs |
removeProfileSection( iniFile, section ) | Remove an entire section |
removeProfileString( iniFile, section, entry ) | Remove a single entry |
Reading an INI File
[General]
appName=MyApplication
version=1.2.3
debug=false
[Database]
host=localhost
port=5432
dbname=myapp
[Logging]
logLevel=DEBUG
logFile=/var/log/myapp.log
appName = getProfileString( "/app/config/app.ini", "General", "appName" )
host = getProfileString( "/app/config/app.ini", "Database", "host" )
port = getProfileString( "/app/config/app.ini", "Database", "port" )
missingValue = getProfileString( "/app/config/app.ini", "General", "nonExistent" )
dbConfig = getProfileSection( "/app/config/app.ini", "Database" )
allConfig = getProfileSections( "/app/config/app.ini" )
Writing an INI File
setProfileString( "/app/config/app.ini", "General", "debug", "true" )
setProfileString( "/app/config/app.ini", "Cache", "enabled", "true" )
setProfileString( "/app/config/app.ini", "Cache", "ttl", "300" )
setProfileString( "/app/config/app.ini", "Cache", "provider", "redis" )
Fluent IniFile Object API
var ini = getIniFile( "/app/config/settings.ini" )
ini.createSection( "MySettings" )
ini.setEntry( "MySettings", "timeout", "30" )
ini.setEntry( "MySettings", "retries", "3" )
ini.setEntry( "MySettings", "endpoint", "https://api.example.com" )
timeout = ini.getEntry( "MySettings", "timeout" )
ini.removeEntry( "MySettings", "retries" )
ini.removeSection( "OldSettings" )
Config File Pattern
env = server.system.environment.APP_ENV ?: "development"
config = getProfileSections( "/app/config/#env#.ini" )
println( config.Database.host )
println( config.General.appName )
Common Pitfalls
- ✅ All values returned from INI files are strings — convert to numeric/boolean as needed:
val( port )
- ❌ INI files do not support nested sections — use YAML (
bx-yaml) for hierarchical config
- ✅
getIniFile() creates the file if it doesn't exist — safe for first-time setup
- ✅
getProfileString() returns an empty string for missing entries — always check if empty when the value is required