Garry's Mod Wiki

file.Exists

boolean file.Exists( string name, string gamePath )

Description

Returns a boolean of whether the file or directory exists or not.

This will sometimes return false clientside for directories received from the server via a clientside lua file. You can work around this by using file.Find 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).

Issue Tracker: 1038

Arguments

1 string name
The file or directory's name.
2 string gamePath
The path to look for the files and directories in. See this list for a list of valid paths.

Returns

1 boolean
Returns true if the file exists and false if it does not.

Example

Prints whether the data folder exists in the base directory.

print( file.Exists( "data", "GAME" ) )
Output: true

Example

Workaround for issue #1038.

local _, dirs = file.Find( "path/to/dir*", "LUA" ) if dirs ~= nil and table.HasValue( dirs, "dir" ) then print( "Directory found!" ) end

Page Links


Special Pages


Wikis

?

Render Time: 85ms

DB GetPage 52
Generate Html 11
SaveChanges (1) 8
Render Body 0
Render Sidebar 11