fs.dirΒΆ

string,table filename,stat fs.dir ( string directory , [nil|string|table] pattern )

Iterates over the given directory

This function iterates over the files and directory in a given path. Pattern check is optionnal, and is either a string or a list of strings. Patterns are lua simple patterns, with files appended with ':reg' and directories appended with ':dir'. For instance, a regular file named 'blahblah.txt' will be matched as 'blahblah.txt:reg', while a directory name 'mydirectory' will be matched as 'mydirectory:dir'. Example:

-- iterates all files and directory
for filename, stat in fs.dir ("c:/path"do
    print (filename)
end
-- iterates over files and directory matching "guerilla"
for filename, stat in fs.dir ("c:/path""guerilla"do
    print (filename)
end
-- iterates over regular files with ".gproject" at the end
for filename, stat in fs.dir ("c:/path""%.gproject:reg"do
    print (filename)
end
-- iterates over directories matching ".CVS" or ".svn"
for filename, stat in fs.dir ("c:/path", {"^%.CVS:dir""^%.CVS:dir"}) do
    print (filename)
end
Arguments:

  • directory the directory path to iterate on
  • pattern the optional pattern to match

Return:

  • filename,stat