# exist

Returns an integer (R) based on whether a variable, function, directory, or file with the name s exists in the current session.

## Syntax

R = exist(s)

R = exist(s, category)

## Inputs

s
Type: string
opt (optional)
Input specifying the category which will be searched for the existence of s. Valid values are:
'var'
Searches for variables.
'builtin'
Searches only for functions.
'dir'
Searches for directories on disk.
'file'
Searches for files on disk.
'class' is for compatibility purposes and is not used to specify any category. If no category is given, the first match for the name in the order of variable, function, dir, or file is returned.
Type: string

## Outputs

R
The value of R is one of the following:
0
s does not exist
1
s is a data variable
2
s is a file in the current directory or search path
5
s is a built-in function
7
s is a directory in the current directory or search path
103
s is a function.
Type: integer
When searching for directories and files, the current working directory and every directory in the current search path is checked. If s is a directory name found in any of these directories, exist will return 7. Otherwise, if s is a file name found in any of these directories, exist will return 2.

## Examples

Search in all variables, functions, directories, and files:
function myfunc()
disp('In myfunc')
end
R = exist('myfunc')
R = 103