Garry's Mod Wiki

Revision Difference

file.Find#547432

<function name="Find" parent="file" type="libraryfunc"> <description>Returns a list of files and directories inside a single folder.</description> <realm>Shared and Menu</realm> <args> <arg name="name" type="string">The wildcard to search for. `models/*.mdl` will list **.mdl** files in the `models/` folder. <arg name="name" type="string">The wildcard to search for. `models/*.mdl` will list **.mdl** files in the `models/` folder.</arg> <arg name="path" type="string">The path to look for the files and directories in. See <page text="this list">File_Search_Paths</page> for a list of valid paths.</arg> <arg name="sorting" type="string" default="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. <bug issue="5250">This argument is automatically enforced to `nameasc` when the path argument is set to `LUA`. **This is fixed in the next update**.</bug> </arg> </args> <rets> <ret name="" type="table">A table of found files, or `nil` if the path is invalid</ret> <ret name="" type="table">A table of found directories, or `nil` if the path is invalid</ret> </rets> </function> <example> <description>Prints the first file and the first directory in the `data` folder.</description> <code> local files, directories = file.Find( "*", "DATA" ) print( "File: " .. files[1], "Folder: " .. directories[1] ) </code> <output> ``` File: helloworld.txt Folder: ctp ``` </output> </example>