Guest User

Untitled

a guest
Nov 25th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.82 KB | None | 0 0
  1. function ls(path,opts_in)
  2.     local opts={
  3.         msglimit=50,
  4.         msgtimeout=100000,
  5.     }
  6.     if opts_in then
  7.         for k,v in pairs(opts_in) do
  8.             opts[k]=v
  9.         end
  10.     end
  11.     local t,msg=os.listdir(path,opts.listall)
  12.     if not t then
  13.         return false,msg
  14.     end
  15.     local b=msg_batcher{
  16.         batchsize=opts.msglimit,
  17.         timeoute=opts.msgtimeout
  18.     }
  19.     if path=='A/' then
  20.         path = 'A'
  21.     end
  22.     for i,v in ipairs(t) do
  23.         if not opts.match or string.match(v,opts.match) then
  24.             if opts.stat then
  25.                 local st,msg=os.stat(path..'/'..v)
  26.                 if not st then
  27.                     return false,msg
  28.                 end
  29.                 if opts.stat == '/' then
  30.                     if st.is_dir then
  31.                         b:write(v .. '/')
  32.                     else
  33.                         b:write(v)
  34.                     end
  35.                 elseif opts.stat == '*' then
  36.                     st.name=v
  37.                     b:write(st)
  38.                 end
  39.             else
  40.                 b:write(t[i])
  41.             end
  42.         end
  43.     end
  44.     b:flush()
  45.     return true
  46. end
Add Comment
Please, Sign In to add comment