lubyk logo

Lubyk documentation

Directory helper

This is a helper to access/glob directory trees. It requires 'lfs' (lua filesystem).

Dependencies

  • lfs

Class functions

.new (path)

Create a new directory helper pointing at path.

Methods

:glob (pattern, max_depth)

Return an iterator to recursively find files matching pattern in the directory. The pattern syntax is the same as string.match. Recursivity can be altered by setting max_depth argument. 0 = do not enter sub-directories. Default value for max_depth is math.huge.

-- Find paths ending in ".lua".
for path in lub.Dir('lub'):glob '%.lua$' do
  print(path)
end
--> lub/Dir.lua
--> lub/Doc.lua
--> ...

:list ()

Return an iterator over the paths in the directory. The returned values are paths, not just filenames.

for file in lub.Dir('lib'):list() do
  print(file)
end
--> lib/foo
--> lib/foo.lua

:contains (pattern)

Return true if there is at least one child in the directory that matches pattern.