lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


lfs.dir returns context object startign i think from 1.6 version.
So more accurate example will be

local dir_next, dir, path = lfs.dir(path) while true do path = dir_next(dir, path) if not path then if dir then dir:close() end break end ... end


чт, 6 сент. 2018 г. в 23:50, Dirk Laurie <dirk.laurie@gmail.com>:
Op Do., 6 Sep. 2018 om 22:40 het Robert McLay <mclay@tacc.utexas.edu> geskryf:
>
> I have some code which does this under unix:
>
>      local path = "/path/to/somewhere"
>      local lfs = require("luafilesystem")
>      local posix = require("posix")
>      if (posix.access(path,"x")) then
>         for f in lfs.dir(path) do
>            ...
>         end
>      end
>
> The problem is that between the posix.access() test and the lfs.dir() call the permissions on path could change.
>
> What I would like instead is some way to ignore the error that lfs.dir() is causing.  Normally one can ignore errors with pcall() but I don't see how to use pcall with an iterator like lfs.dir().

iterator = lfs.dir()
while true do
  local f = pcall(iterator)
  if not p then break end
  ...
end