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

Help with tables and textutils.pagedTabulate()

Started by GuardianFox, 31 December 2013 - 12:46 PM
GuardianFox #1
Posted 31 December 2013 - 01:46 PM
So I want to make a program that when run takes the directory you specify and prints out a tabulated list of file names and file sizes (listing directories as 'DIR' instead of a file size). It also prints the name of the drive, free space, and adds up the used space in the directory specified. The problem I come across is that I end up building a table of tables that I want to pass to textutils.pagedTabulate() but of course, it can't take that.


if (...)~=nil then
  path=(...)
else
  path=shell.dir()
end
header={'FILE','SIZE'}
files = fs.list(path)
totalSize = 0
fileTable={}
i=0
for _, file in ipairs(files) do
  i=i+1
  fileTable[i]={}
  fileTable[i][1]=file
  if fs.isDir(file)~=false then
	fileTable[i][2]='DIR'
  else
	totalSize=totalSize+fs.getSize(path..'/'..file)
	fileTable[i][2]=fs.getSize(path..'/'..file)
  end
end
textutils.pagedTabulate(header)
for i=0,#fileTable do
  textutils.pagedTabulate(fileTable[i])
end
drive={'DRIVE','"'..fs.getDrive(path)..'"'}
freeBytes={'FREE BYTES',fs.getFreeSpace(path)}
totalBytes={'TOTAL BYTES',totalSize}
textutils.pagedTabulate(drive,freeBytes,totalBytes)

Right now my code prints out what I need, and the format for the header and extra data at the bottom is correct, because those are formatted correctly, however I have fileTable[#][#] I can't figure out how to pass this to textutils.pagedTabulate() as fileTable[1],fileTable[2],etc for however many tables there are.
Bomb Bloke #2
Posted 31 December 2013 - 07:26 PM
textutils.pagedTabulate(unpack(fileTable)) would pass the entire contents in one go, if that's what you're meaning.