Garry's Mod Wiki

Revision Difference

file.IsDir#528431

<function name="IsDir" parent="file" type="libraryfunc"> <description>Returns whether the given file is a directory or not.</description> <description>Returns whether the given file is a directory or not. <bug issue="1038"> This will sometimes return false clientside for directories received from the server via a clientside lua file. You can work around this by using <page>file.Find</page> with the path to the directory followed by a wildcard (no trailing forward slash) and see if the directory is inside the returned directories table. <example> <code> local _, dirs = file.Find("path/to/dir*", "LUA") if dirs != nil and table.HasValue(dirs, "dir") then print("Directory found!") end </code> </example> </bug> </description> <realm>Shared and Menu</realm> <args> <arg name="fileName" type="string">The file or directory's name.</arg> <arg name="path" type="string">The path of where to look for the file. * "GAME" Structured like base folder (garrysmod/), searches all the mounted content (main folder, addons, mounted games etc) * "LUA" or "lsv" - All Lua folders (lua/) including gamesmodes and addons * "DATA" Data folder (garrysmod/data) * "MOD" Strictly the game folder (garrysmod/), ignores mounting.</arg> </args> <rets> <ret name="" type="boolean">True if the given path is a directory or false if it is a file.</ret> </rets> </function> <example> <description>Prints if `helloworld.txt` is a directory.</description> <code>print( file.IsDir("helloworld.txt", "DATA") )</code> <output>false</output> </example> </example>