system_io
system_io offers functionality of files, directories, paths and drives.
disks
This table gives us information about disks:
disks.list() - returns index table of all connected drives
disks.get_info(index) - returns drive info in a table
| Include("system_io")
for _, id in pairs(disk.list()) do
local info = disk.get_info(id)
console.println("Name: " .. info["name"])
console.println("Drive size: " .. info["size"]) -- In bytes
console.println("Used: " .. info["used_space"]) -- In bytes
console.println("Available: " .. info["size"] - info["used_space"])
end
|
directory
Offers directory functionality:
| Include("system_io")
local dir = directory.create(0, "/temp") -- 0 is the drive index
console.println("Directory owner: " .. dir["owner"])
if directory.exists(0, "/temp") then
directory.delete(0, "/temp")
else
console.println(0, "Directory disappeared 🤨")
end
|
file
Offers file functionality:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 | Include("system_io")
local dir = file.create(0, "/temp") -- 0 is the drive index
console.println("File owner: " .. dir["owner"])
console.print("Your name: ")
local name = console.readln()
file.write_text(0, "/temp", name)
name = file.read_text(0, "/temp")
console.println("Your name is " .. name .. "! I knew it!!!")
if directory.exists(0, "/temp") then
directory.delete(0, "/temp")
else
console.println(0, "File disappeared 🤨")
end
|