SysLib — System Library
System-level functions for interacting with the operating system, file system, and environment. Designed for cross-platform applications running on Windows, macOS, Linux, iOS, and Android.
| Category | Count | Description |
| Command Line | 2 | paramcount, paramstr$ |
| File Operations | 2 | fileexists, kill |
| Directory Operations | 4 | chdir, mkdir, rmdir, forcedirectories |
| Path Manipulation | 4 | extractfilename$, extractfilepath$, extractfileext$, changefileext$ |
| System Paths | 7 | homepath$, documentspath$, temppath$, cachepath$, publicpath$, librarypath$, shareddocumentspath$ |
| Media Paths | 10 | picturespath$, musicpath$, moviespath$, downloadspath$, camerapath$ (+ shared variants) |
| Mobile Paths | 4 | alarmspath$, ringtonespath$ (+ shared variants) |
| File Name Generation | 3 | randomfilename$, guidfilename$, tempfilename$ |
| Path Separators | 3 | dirseparator$, altseparator$, pathseparator$ |
| Environment | 1 | environ$ |
| Colors | 3 | color, alphacolor, colortostr$ |
Command-Line Functions
| Function | Signature | Description |
paramcount() | paramcount@ | Number of command-line arguments (excluding program name) |
paramstr$(index) | paramstr$@n | Get argument at index (0 = program path, 1+ = args) |
' If called: myapp.exe file.txt -verbose
println "Program: "; paramstr$(0)
println "Arg 1: "; paramstr$(1) ' "file.txt"
println "Arg 2: "; paramstr$(2) ' "-verbose"
println "Total args: "; paramcount()
File Operations
| Function | Signature | Description |
fileexists(file$, followLinks) | fileexists@$n | Check if file exists (1=yes, 0=no) |
kill(file$) | kill@$ | Delete a file (1=success, 0=fail) |
if fileexists("config.txt", 0) = 1 then
println "Config file found"
endif
' Follow symbolic links
if fileexists("link_to_file", 1) = 1 then
println "Target exists"
endif
' Delete a file
if kill("temp.dat") = 1 then
println "File deleted"
else
println "Delete failed"
endif
⚠ Warning: kill() permanently deletes the file. It is not sent to the Recycle Bin / Trash.
Directory Operations
| Function | Signature | Description |
chdir(path$) | chdir@$ | Change current working directory |
mkdir(path$) | mkdir@$ | Create a new directory (parent must exist) |
rmdir(path$) | rmdir@$ | Remove an empty directory |
forcedirectories(path$) | forcedirectories@$ | Create full directory path including parents (1=success, 0=fail) |
' Change to documents folder
chdir(documentspath$())
' Create a single directory
mkdir("NewFolder")
' Create nested directories (all at once)
path$ = documentspath$() + dirseparator$() + "Projects" + dirseparator$() + "MyApp" + dirseparator$() + "Data"
if forcedirectories(path$) = 1 then
println "Directory structure created"
endif
' Remove an empty directory
rmdir("EmptyFolder")
ⓘ Note: mkdir() requires parent directories to already exist. Use forcedirectories() to create the entire path at once.
Path Manipulation
| Function | Signature | Description |
extractfilename$(path$) | extractfilename$@$ | File name with extension from full path |
extractfilepath$(path$) | extractfilepath$@$ | Directory portion from full path |
extractfileext$(file$) | extractfileext$@$ | Extension including the dot |
changefileext$(file$, ext$) | changefileext$@$$ | Change file extension |
path$ = "/home/user/documents/report.pdf"
println extractfilename$(path$) ' report.pdf
println extractfilepath$(path$) ' /home/user/documents/
println extractfileext$(path$) ' .pdf
println changefileext$(path$, ".bak") ' /home/user/documents/report.bak
println extractfileext$("README") ' (empty string)
System Path Functions
Platform-specific standard directories. Returns appropriate paths on each OS.
| Function | Signature | Description |
homepath$() | homepath$@ | User home directory |
documentspath$() | documentspath$@ | User documents folder |
shareddocumentspath$() | shareddocumentspath$@ | Shared documents folder |
temppath$() | temppath$@ | Temporary files directory |
cachepath$() | cachepath$@ | Application cache directory |
publicpath$() | publicpath$@ | Public/shared storage |
librarypath$() | librarypath$@ | Application library/support path |
| Function | Windows | macOS | Linux |
homepath$() | C:\Users\Name | /Users/Name | /home/name |
documentspath$() | ...\Documents | .../Documents | .../Documents |
temppath$() | %TEMP% | /tmp | /tmp |
cachepath$() | App-specific | App-specific | App-specific |
librarypath$() | App-specific | ~/Library | App-specific |
println "Home: "; homepath$()
println "Documents: "; documentspath$()
println "Temp: "; temppath$()
println "Cache: "; cachepath$()
println "Library: "; librarypath$()
Mobile-Specific Paths
| Function | Signature | Description |
alarmspath$() | alarmspath$@ | Alarms sound folder |
sharedalarmspath$() | sharedalarmspath$@ | Shared alarms folder |
ringtonespath$() | ringtonespath$@ | Ringtones folder |
sharedringtonespath$() | sharedringtonespath$@ | Shared ringtones folder |
ⓘ Note: These paths are primarily relevant on Android. On desktop platforms they may return empty or app-specific paths.
File Name Generation
| Function | Signature | Description |
randomfilename$() | randomfilename$@ | Random file name (e.g. tmpA1B2C.tmp) |
guidfilename$(useSep) | guidfilename$@n | GUID-based unique name (1=with hyphens, 0=without) |
tempfilename$() | tempfilename$@ | Create temp file and return its full path |
println randomfilename$() ' e.g. "tmpA1B2C.tmp"
println guidfilename$(1) ' {A1B2C3D4-E5F6-7890-...}
println guidfilename$(0) ' {A1B2C3D4E5F67890...}
' tempfilename$ actually creates the file!
tempFile$ = tempfilename$()
println "Temp file: "; tempFile$
' Clean up when done
kill(tempFile$)
⚠ Warning: tempfilename$() actually creates the file on disk. Remember to delete it with kill() when done.
Path Separator Functions
| Function | Signature | Description |
dirseparator$() | dirseparator$@ | Directory separator (\ on Windows, / on others) |
altseparator$() | altseparator$@ | Alternate separator (/ on Windows, same as dirseparator$ elsewhere) |
pathseparator$() | pathseparator$@ | PATH list separator (; on Windows, : on others) |
| Function | Windows | macOS / Linux |
dirseparator$() | \ | / |
altseparator$() | / | / |
pathseparator$() | ; | : |
' Always build paths with dirseparator$()
path$ = documentspath$() + dirseparator$() + "MyApp" + dirseparator$() + "data.txt"
println path$
ⓘ Note: Always use dirseparator$() when building paths. Never hardcode \ or / if you want cross-platform compatibility.
Environment Variables
| Function | Signature | Description |
environ$(name$) | environ$@$ | Get environment variable value (empty string if not found) |
| Variable | Platform | Description |
USERNAME | Windows | Current user name |
USER | Linux / macOS | Current user name |
HOME | Linux / macOS | Home directory |
USERPROFILE | Windows | User profile directory |
PATH | All | Executable search paths |
TEMP / TMP | Windows | Temporary directory |
TMPDIR | macOS / Linux | Temporary directory |
' Cross-platform user name
user$ = environ$("USERNAME")
if len(user$) = 0 then
user$ = environ$("USER")
endif
println "User: "; user$
' Cross-platform home
home$ = environ$("HOME")
if len(home$) = 0 then
home$ = environ$("USERPROFILE")
endif
println "Home: "; home$
Color Functions
| Function | Signature | Description |
color(name$) | color@$ | Color name or hex string to numeric value |
alphacolor(name$) | alphacolor@$ | Color with alpha channel to numeric value |
colortostr$(n) | colortostr$@n | Numeric color value back to string |
' Named colors
c = color("Red")
c = color("clBlue")
c = color("$FF0000") ' Hex format
' With alpha
c = alphacolor("Red")
c = alphacolor("#80FF0000") ' Semi-transparent red
' Convert back to string
c = color("Navy")
println "Navy: "; c
println "Name: "; colortostr$(c)
ⓘ Note: Supported color names include: Black, Maroon, Green, Olive, Navy, Purple, Teal, Gray, Silver, Red, Lime, Yellow, Blue, Fuchsia, Aqua, White, and many more. Hex formats $RRGGBB and #RRGGBB are also accepted.
Complete Examples
Cross-Platform Path Builder
' Build paths that work on any platform
function buildPath$(base$, parts$) local result$, sep$
sep$ = dirseparator$()
result$ = base$
if right$(result$) = sep$ then
result$ = left$(result$, len(result$) - 1)
endif
result$ = result$ + sep$ + parts$
return result$
endfunction
println "Home: "; homepath$()
println "Documents: "; documentspath$()
println "Temp: "; temppath$()
appData$ = buildPath$(documentspath$(), "MyApp")
println "App data: "; appData$
configFile$ = buildPath$(appData$, "config.txt")
println "Config: "; configFile$
Command-Line Argument Processor
' Process command-line arguments
println "Program: "; paramstr$(0)
println "Args: "; paramcount()
if paramcount() > 0 then
for i = 1 to paramcount()
arg$ = paramstr$(i)
print " ["; i; "] "; arg$
if left$(arg$) = "-" then
println " (flag)"
else
println ""
endif
next
else
println "No arguments provided."
println "Usage: program [options] [files...]"
endif
File Manager Operations
' File management utilities
function createAppFolder$() local path$
path$ = documentspath$() + dirseparator$() + "Plan9BasicApp"
if forcedirectories(path$) = 1 then
return path$
else
return ""
endif
endfunction
function fileInfo$(filename$) local info$
info$ = "File: " + extractfilename$(filename$) + chr$(10)
info$ = info$ + "Path: " + extractfilepath$(filename$) + chr$(10)
info$ = info$ + "Ext: " + extractfileext$(filename$) + chr$(10)
info$ = info$ + "Exists: " + str$(fileexists(filename$, 0))
return info$
endfunction
appFolder$ = createAppFolder$()
println "App folder: "; appFolder$
testPath$ = documentspath$() + dirseparator$() + "test.txt"
println fileInfo$(testPath$)
println "As .bak: "; changefileext$(testPath$, ".bak")
Temporary File Handling
' Working with temporary files
println "Temp dir: "; temppath$()
println ""
println "Random names:"
for i = 1 to 3
println " "; randomfilename$()
next
println ""
println "GUID names:"
println " With sep: "; guidfilename$(1)
println " No sep: "; guidfilename$(0)
println ""
tempFile$ = tempfilename$()
println "Created: "; tempFile$
if fileexists(tempFile$, 0) = 1 then
println "Exists: Yes"
if kill(tempFile$) = 1 then
println "Deleted OK"
endif
endif
Environment Information
' System environment overview
user$ = environ$("USERNAME")
if len(user$) = 0 then
user$ = environ$("USER")
endif
println "User: "; user$
println "Home (func): "; homepath$()
println ""
println "Separator: ["; dirseparator$(); "]"
println "Path sep: ["; pathseparator$(); "]"
println ""
println "System Paths:"
println " Documents: "; documentspath$()
println " Pictures: "; picturespath$()
println " Music: "; musicpath$()
println " Downloads: "; downloadspath$()
println " Temp: "; temppath$()
println " Cache: "; cachepath$()
Quick Reference
| Function | Signature | Description |
paramcount() / paramstr$(n) | *@[n] | Command-line arguments |
fileexists(f$, follow) | fileexists@$n | Check file exists (1/0) |
kill(f$) | kill@$ | Delete file (1=success) |
chdir(p$) / mkdir(p$) / rmdir(p$) | *@$ | Directory operations |
forcedirectories(p$) | forcedirectories@$ | Create full path (1=success) |
extractfilename$(p$) | extractfilename$@$ | Filename from path |
extractfilepath$(p$) | extractfilepath$@$ | Directory from path |
extractfileext$(f$) | extractfileext$@$ | Extension (with dot) |
changefileext$(f$, e$) | changefileext$@$$ | Change extension |
homepath$() / documentspath$() | *$@ | Core system paths |
temppath$() / cachepath$() | *$@ | Temp and cache paths |
picturespath$() / musicpath$() | *$@ | Media paths |
moviespath$() / downloadspath$() | *$@ | Media paths |
camerapath$() / alarmspath$() / ringtonespath$() | *$@ | Mobile paths |
randomfilename$() | randomfilename$@ | Random file name |
guidfilename$(sep) | guidfilename$@n | GUID-based name |
tempfilename$() | tempfilename$@ | Create temp file, return path |
dirseparator$() / pathseparator$() | *$@ | Platform separators |
environ$(name$) | environ$@$ | Environment variable |
color(s$) / alphacolor(s$) | *@$ | Color name/hex to number |
colortostr$(n) | colortostr$@n | Number to color string |
43 functions across 11 categories.