This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
CastleMan2000's profile picture

MemUtility 2.0

Started by CastleMan2000, 24 September 2012 - 06:47 PM
CastleMan2000 #1
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.



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.
wilcomega #2
Posted 25 September 2012 - 08:28 PM
nice one
i am going to check how much BlueFrames takes up
CastleMan2000 #3
Posted 25 September 2012 - 09:03 PM
I think I could update the program for file size, let me get right to that.

EDIT: Done! MemUtility 2.0.
wilcomega #4
Posted 27 September 2012 - 03:43 PM
when you have my BlueFrames OS 1.4 BETA installed on ur pc, you have about 2 mb free
CastleMan2000 #5
Posted 27 September 2012 - 09:28 PM
How about KB? The free space is rounded up.