Advertisement
Guest User

sfifs v0_0_1

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