Advertisement
LDDestroier

(CC) Get hard drive size

May 18th, 2016
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.21 KB | None | 0 0
  1. listAll = function(_path, _files, noredundant, excludeFiles)
  2.     local thisProgram = ""
  3.     if shell then
  4.         thisProgram = shell.getRunningProgram()
  5.     end
  6.     local path = _path or ""
  7.     local files = _files or {}
  8.     if #path > 1 then table.insert(files, path) end
  9.     for _, file in ipairs(fs.list(path)) do
  10.         local path = fs.combine(path, file)
  11.         if (file ~= thisProgram) and (not fs.isReadOnly(file)) then
  12.             local guud = true
  13.             for a = 1, #excludeFiles do
  14.                 if excludeFiles[a] == file then
  15.                     guud = false
  16.                     break
  17.                 end
  18.             end
  19.             if guud then
  20.                 if fs.isDir(path) then
  21.                     listAll(path, files, noredundant, excludeFiles)
  22.                 else
  23.                     table.insert(files, path)
  24.                 end
  25.             end
  26.         end
  27.     end
  28.     if noredundant then
  29.         for a = 1, #files do
  30.             if fs.isDir(tostring(files[a])) then
  31.                 if #fs.list(tostring(files[a])) ~= 0 then
  32.                     table.remove(files,a)
  33.                 end
  34.             end
  35.         end
  36.     end
  37.     return files
  38. end
  39.  
  40. local tArg = {...}
  41.  
  42. function getAllSpace(path)
  43.     local freespace = fs.getFreeSpace(path or "")
  44.     local filetree = listAll(path or "",{},false,{})
  45.     for a = 1, #filetree do
  46.         if not fs.isDir(filetree[a]) then
  47.             freespace = freespace + fs.getSize(filetree[a])
  48.         end
  49.     end
  50. end
  51.  
  52. print(getAllSpace(tArg[1]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement