Garry's Mod Wiki

file.Find

  table, table file.Find( string name, string path, string sorting = "nameasc" )

Description

Returns a list of files and directories inside a single folder.

It seems that paths with capital letters (e.g. lua/MyFolder/*) don't work as expected on Linux.

Arguments

1 string name
The wildcard to search for. models/*.mdl will list .mdl files in the models/ folder.
2 string path
The path to look for the files and directories in. See this list for a list of valid paths.
3 string sorting = "nameasc"
The sorting to be used, optional.
  • nameasc sort the files ascending by name.
  • namedesc sort the files descending by name.
  • dateasc sort the files ascending by date.
  • datedesc sort the files descending by date.

Returns

1 table
A table of found files, or nil if the path is invalid
2 table
A table of found directories, or nil if the path is invalid

Example

Prints the first file and the first directory in the data folder.

local files, directories = file.Find( "*", "DATA" ) print( "File: " .. files[1], "Folder: " .. directories[1] )
Output:
File: helloworld.txt Folder: ctp