Garry's Mod Wiki

file.Exists

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 _, folders = file.Find( "path/to/dir*", "LUA" ) for _, v in ipairs( folders ) do if v == "dir" then print( "Directory found!" ) break end end

Special Pages


Wikis

?

Render Time: 57ms

DB GetPage 37
Generate Html 6
SaveChanges (1) 5
Render Body 0
Render Sidebar 6