Dapi IO
import¶
to start, you need to import the api in your script, you can do it with
local dapi_io = require("dapi_io")
zip¶
unzip¶
get_dafault_directories¶
a function which returns a lua table containing a lot of dafault directories
Usage
local dir = dapi_io.get_default_directories()
print(dir.home)
Path Overview
Name | Windows | Linux |
---|---|---|
home | C:\Users\username | /home/username |
desktop | ||
documents | ~/Documents | |
downloads | ~/Downloads | |
music | ||
videos | ||
pictures | ||
config | %APPDATA% | ~/.config |
data | %APPDATA% | ~/.local/share |
localdata | %LOCALAPPDATA% | ~/.local/share |
cache | C:\Users\username\AppData\Local\Cache | ~/.cache |
create_dir¶
function to create a directory recursivly
Usage
dapi_io.create_dir("Wtf")
delete_dir¶
function to delete a directory recursivly
Usage
dapi_io.delete_dir("Wtf")
copy_file¶
function to copy a file
Usage
dapi_io.copy_file("hallo.txt", "wtf/hallo.txt")
copy_dir¶
function to copy a directory from one place to another place
Usage
dapi_io.copy_dir("/dir", "/dir2")
create_file¶
write_file¶
append_file¶
function to add data to an existing file
dapi_io.append_file("/tmp/test.txt", "Zeile 1\n")
dapi_io.append_file("/tmp/test.txt", "Zeile 2\n")
get_file_size¶
a function to get the size of an file
Usage
dapi_os.write_file("wtf.txt")
local size = dapi_os.get_file_size("wtf.txt")
print(size)
read_line()
¶
Reads a text file and returns its contents as a Lua table, line by line. Optionally, a maximum number of lines can be specified.
Lua Function Signature
lines = read_line(path [, max_lines])
Parameters
Name | Type | Required | Description |
---|---|---|---|
path |
string |
Yes | The file path to read from |
max_lines |
number |
No | Maximum number of lines to read (optional) |
Return Value
Returns a Lua table
where each line of the file is stored as a string:
Index | Value |
---|---|
1 |
First line |
2 |
Second line |
Example (in Lua)
local lines = read_line("example.txt", 5)
for i, line in ipairs(lines) do
print(i .. ": " .. line)
end
Error Handling
- If the file cannot be opened, an error is raised:
"Open file error: <details>"
- If a line cannot be read, an error is raised:
"Read line error: <details>"
- File reading stops early if
max_lines
is provided and reached.