OS Namespace
Theos namespace provides file system operations.
os.read_file()
Read the contents of a file.Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Path to the file to read |
Returns
string - File contents, or null if failed
Example
os.write_file()
Write content to a file (overwrites existing file).Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Path to the file to write |
content | string | Content to write to the file |
Returns
boolean - true if successful
Example
os.append_file()
Append content to a file (creates file if it doesn’t exist).Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Path to the file |
content | string | Content to append |
Returns
boolean - true if successful
Example
os.delete_file()
Delete a file.Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Path to the file to delete |
Returns
boolean - true if successful
Example
os.exists()
Check if a file or directory exists.Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Path to check |
Returns
boolean - true if exists
Example
os.list_dir()
List contents of a directory.Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Directory path |
Returns
Array of file/directory objects with properties:name(string) - File/directory nameis_dir(boolean) - Whether it’s a directorysize(number) - File size in bytesmod_time(number) - Last modified time (Unix timestamp)
Example
os.create_dir()
Create a directory (including parent directories if needed).Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Directory path to create |
Returns
boolean - true if successful
Example
os.remove_dir()
Remove a directory and all its contents recursively.Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Directory path to remove |
Returns
boolean - true if successful
Warning
This operation is irreversible and removes all subdirectories and files!os.get_cwd()
Get the current working directory.Syntax
Returns
string - Current working directory path
Example
os.join_path()
Join path components into a single path.Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
...paths | string | Path components to join |
Returns
string - Joined path
Example
os.basename()
Get the filename from a path.Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | File path |
Returns
string - Filename (last element of path)
Example
os.dirname()
Get the directory from a path.Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | File path |
Returns
string - Directory path
Example
os.file_info()
Get detailed information about a file or directory.Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | File/directory path |
Returns
Object with properties:name(string) - Namesize(number) - Size in bytesis_dir(boolean) - Whether it’s a directorymod_time(number) - Last modified time (Unix timestamp)mode(string) - File permissions (e.g., “-rw-r—r—”)
null if file doesn’t exist.
Example
os.abs_path()
Get the absolute path from a relative path.Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Relative or absolute path |
Returns
string - Absolute path
Example
os.rename()
Rename or move a file/directory.Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
oldPath | string | Current path |
newPath | string | New path |
Returns
boolean - true if successful