MeXaN1cK

SizeOfFolder_AndSearchFile

Jul 31st, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1. local fs = require("filesystem")
  2. local sh = require("shell")
  3. local serialization = require("serialization")
  4. local args= sh.parse(...)
  5. local uc = require("unicode")
  6.  
  7. name = 'filesystem.lua'
  8.  
  9. function get(path)
  10.   local result = {}
  11.   for value in fs.list(path) do
  12.     local str = path..value
  13.     a,b = string.gsub(str,name,'')
  14.     if b > 0 then print (str) end
  15.     if uc.sub(path..value,uc.len(path..value),uc.len(path..value)) ~= '/' or fs.isDirectory(path..value) == false then
  16.       result[#result+1] = value
  17.     else
  18.      -- print(path..value)
  19.       arr = get(path..value)
  20.       result[path..value] = arr
  21.     end
  22.   end
  23.   return result
  24. end
  25.  
  26. local path = tostring(args[1])
  27.  
  28. finders = {}
  29.  
  30. local arr = get(path)
  31.  
  32. local function find(name)
  33. for val,val2 in pairs(arr) do
  34.   if type(val) == 'string' then
  35.     if uc.sub(val,uc.len(val),uc.len(val)) == '/' then
  36.       for value in fs.list(val) do
  37.         if uc.sub(value,uc.len(value)-uc.len(name)+1,uc.len(value)) == tostring(name)  then
  38.           print(value)
  39.         end
  40.       end
  41.     end
  42. end
  43. end
  44. end
  45.  
  46. local function size()
  47. local size = 0
  48. for val,val2 in pairs(arr) do
  49.   if type(val) == 'string' then
  50.     if uc.sub(val,uc.len(val),uc.len(val)) == '/' then
  51.       for value in fs.list(val) do
  52.        -- print(val..value)
  53.         size = size + fs.size(val..value)
  54.       end
  55.     else
  56.       size = size + fs.size(val..value)
  57.     end
  58.   elseif type(val) == 'number' then
  59.     size = size + fs.size(path..arr[val])
  60.   end
  61. end
  62.  
  63. print(size)
  64. end
  65.  
  66. --print(serialization.serialize(get(tostring(args[1]))))
Add Comment
Please, Sign In to add comment