Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin get 14xf463S FileManager
- FM = {}
- function FM.getDiskByLabel(label)
- for _, side in ipairs(peripheral.getNames()) do
- if peripheral.getType(side) == "drive" then
- local disk = peripheral.wrap(side)
- if disk.getDiskLabel() == label then
- return disk, disk.getMountPath()
- elseif disk.getDiskLabel() == nil and label == "Floppy Disk" then
- return disk, disk.getMountPath()
- end
- end
- end
- return nil, nil
- end
- function FM.resetAllDisks()
- for _, side in ipairs(peripheral.getNames()) do
- if peripheral.getType(side) == "drive" then
- local disk = peripheral.wrap(side)
- local path = disk.getMountPath() .. "/"
- shell.run("delete " .. path .. "*")
- disk.setDiskLabel()
- end
- end
- end
- function FM.getTableSize(dataTable)
- return math.max(512, #textutils.serialize(dataTable, {compact = true}))
- end
- function FM.combineTables(t1, t2)
- for _, val in ipairs(t2) do
- table.insert(t1, val)
- end
- return t1
- end
- function FM.loadFile(filePath)
- if not fs.exists(filePath) then return nil end
- local file = fs.open(filePath, "r")
- data = file.readAll()
- file.close()
- return data
- end
- function FM.saveFile(data, filePath)
- local file = fs.open(filePath, "w")
- file.write(data)
- file.close()
- end
- function FM.saveTable(dataTable, filePath, extracted)
- local file = fs.open(filePath, "w")
- if not extracted then
- file.write(textutils.serialize(dataTable, {compact = true}))
- else
- file.write(textutils.serialize(dataTable))
- end
- file.close()
- end
- function FM.loadTable(filePath)
- if not fs.exists(filePath) then return {} end
- local file = fs.open(filePath, "r")
- local dataTable = textutils.unserialize(file.readAll())
- file.close()
- if dataTable == nil then return {} end
- return dataTable
- end
- function FM.getEmptyDiskAmount()
- local cnt = 0
- for _, side in ipairs(peripheral.getNames()) do
- if peripheral.getType(side) == "drive" then
- local disk = peripheral.wrap(side)
- if disk.getDiskLabel() == nil or label == "Floppy Disk" then
- cnt = cnt + 1
- end
- end
- end
- return cnt
- end
- return FM
Advertisement
Add Comment
Please, Sign In to add comment