Calculating MS space used leads to errors

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
matriculated
Posts: 31
Joined: Sat Mar 04, 2006 1:35 am

Calculating MS space used leads to errors

Post by matriculated »

So, I have this recursive function to find the memory stick space used which also takes into account cluster size but I'm always shy a few megs of space. Can anyone tell me why?

Code: Select all

function MSused(dir)
  local space = 0
  
  --seed the 1st iteration with root of ms
  dir = dir or "ms0:"

  files = System.listDirectory(dir)
  if files == nil then
    -- NOT SURE IF THIS IS ACCURATE, BUT IT'S LESS ACCURATE WHEN LEFT OUT.
    -- I'm assuming that folders take 16k of space (this makes no sense)
    space = 16384
  else    
    for index, file in files do
      -- we convert the filesize to take account of the minimum 32k filesize
      space = space + math.ceil(file.size/32768)*32768
      if file.directory then space = space + MSused(dir .. "/" .. file.name) end
    end
  end
  return space
end
Post Reply