Garry's Mod Wiki

Revision Difference

file.IsDir#551277

<function name="IsDir" parent="file" type="libraryfunc"> <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 (**see second example)**. **This is fixed in the next update.**</bug> ⤶ </description> <realm>Shared and Menu</realm> <args> <arg name="fileName" type="string">The file or directory's name.</arg> <arg name="gamePath" 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> </args> <rets> <ret name="" type="boolean">`true` if the given path is a directory or `false` if it's 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>⤶ <description>Workaround for issue [#1038](https://github.com/Facepunch/garrysmod-issues/issues/1038).</description>⤶ <code> ⤶ local _, folders = file.Find( "path/to/dir*", "LUA" )⤶ ⤶ for _, v in ipairs( folders ) do⤶ if v == "dir" then⤶ print( "Directory found!" )⤶ break⤶ end⤶ end⤶ </code> ⤶ </example>