lua-users home
lua-l archive

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


Ken Smith wrote:
I have found myself in a position where I must use Lua to walk a
directory tree and performing some operation on every file.  Is there
an idiomatic way to do this in Lua?

Since standard C has no interface for dealing with directories, neither does core Lua. However, may people have written libraries which include file system manipulation, including directory iteration.


LuaFileSystem:

  -- http://www.keplerproject.org/luafilesystem/
  require "lfs"
  for name in lfs.dir"/foo" do
    print(name)
  end


lposix:

  -- http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#lposix
  require "lposix"
  for name in posix.files"/foo" do
    print(name)
  end


And there is also the "ex" API:

  -- http://lua-users.org/wiki/ExtensionProposal
  require "ex"
  for entry in os.dir"/foo" do
    print(entry.name)
  end

					-Mark