Posted 24 September 2012 - 08:47 PM
This is MemUtility 2.0, which is slightly improved. Changes include getting file sizes and getting free space in disks.
NOTE: Free space values are rounded UP.
term.clear()
term.setCursorPos(1,1)
local bytesFree = fs.getFreeSpace("/")
local kbFree = math.ceil(bytesFree / 1024)
local mbFree = math.ceil(kbFree / 1024)
if fs.exists("/disk") then
diskFree = fs.getFreeSpace("/disk")
diskKB = math.ceil(diskFree / 1024)
diskMB = math.ceil(diskKB / 1024)
diskPresent = true
end
function getFreeMem()
term.clear()
local bytesFree = fs.getFreeSpace("/")
local kbFree = math.ceil(bytesFree / 1024)
local mbFree = math.ceil(kbFree / 1024)
if fs.exists("/disk") then
diskFree = fs.getFreeSpace("/disk")
diskKB = math.ceil(diskFree / 1024)
diskMB = math.ceil(diskKB / 1024)
diskPresent = true
end
print("|TERMINAL|")
print("Approx. Bytes free: "..bytesFree)
print("Approx. KB free: "..kbFree)
print("Approx. MB free: "..mbFree)
if diskPresent then
print("|DISK|")
print("Approx. Bytes free: "..diskFree)
print("Approx. KB free: "..diskKB)
print("Approx. MB free: "..diskMB)
end
end
function getFileSize(path)
term.clear()
if fs.exists(path) then
local fileSize = fs.getSize(path)
local fileKB = fileSize / 1024
print("|File Size|")
print("In Bytes: "..fileSize)
print("In KB: "..fileKB)
else
error("Path does not exist!")
end
end
term.clear()
print[[
MemUtility 2.0
A. Get free space
B. Get file size
]]
local response = io.read()
if string.upper(response) == "A" then
getFreeMem()
elseif string.upper(response) == "B" then
term.write("Please input path: ")
local sizePath = io.read()
getFileSize(sizePath)
else
print("Invalid input! Please try again.")
end
NOTE: Free space values are rounded UP.