Advertisement
ZNZNCOOP

sfifs v0_0_4

Sep 29th, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.65 KB | None | 0 0
  1. local sfifs = {}
  2.  
  3. sfifs.comp = require("component")
  4.  
  5. function sfifs.getAllFiles(filesystem, path)
  6.    local list = sfifs.comp.list()
  7.    for address, type in pairs(list) do
  8.    if(address == filesystem.address and type == "filesystem") then
  9.    local list = filesystem.list(path)
  10.       local files = {}
  11.       if(#path > 0 and string.sub(path, #path, #path) ~= "/") then
  12.          path = path.."/"
  13.       end
  14.       for i = 1, #list do
  15.           if(filesystem.isDirectory(path.."/"..list[i])) then
  16.              local tmp = sfifs.ginf(filesystem, path.."/"..list[i])
  17.              for v = 1, #tmp do
  18.                 files[#files+1] = tmp[v]
  19.              end
  20.           else
  21.              files[#files+1] = path..list[i]
  22.           end
  23.       end          
  24.       return files
  25.       end
  26.    end
  27. end
  28.  
  29. function sfifs.searchFile(filesystem, path, filename)
  30.    local files = sfifs.getAllFiles(filesystem, path)
  31.    local nowfilename = ""
  32.    local rez = ""
  33.    local filesFound = {}
  34.    if(files ~= nil and #files > 0) then
  35.       for i = 1, #files do
  36.       nowfilename = string.match(files[i], ".+/(.+)")
  37.       if(nowfilename == nil) then
  38.          nowfilename = files[i]
  39.       end
  40.       rez = string.match(nowfilename, filename)
  41.       if(rez ~= nil) then
  42.          filesFound[#filesFound+1] = files[i]
  43.       end
  44.       end
  45.    end
  46.    return filesFound
  47. end
  48.  
  49. function sfifs.ginf(filesystem, path)
  50.    local list = filesystem.list(path)
  51.    local files = {}
  52.    for i = 1,#list do
  53.       if(filesystem.isDirectory(path..list[i])) then
  54.          local tmp = sfifs.ginf(filesystem, path..list[i])
  55.          for v = 1, #tmp do
  56.             files[#files+1] = tmp[v]
  57.          end
  58.       else
  59.          files[#files+1] = path..list[i]
  60.          --print(path..list[i])
  61.       end
  62.    end
  63.    return files
  64. end
  65. return sfifs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement