This section explains how to search for a file in a list of directories (a path), or for an executable file in the standard list of executable file directories.
To search for a user-specific configuration file, See Standard File Names, for the
This function searches for a file whose name is filename in a
list of directories given by path, trying the suffixes in
suffixes. If it finds such a file, it returns the file’s
absolute file name (see Relative File Names); otherwise it returns
The optional argument suffixes gives the list of file-name
suffixes to append to filename when searching.
locate-file tries each possible directory with each of these
suffixes. If suffixes is
(""), then there
are no suffixes, and filename is used only as-is. Typical
values of suffixes are
exec-suffixes (see Subprocess Creation),
the return value of the function
get-load-suffixes (see Load Suffixes).
Typical values for path are
exec-path (see Subprocess Creation) when looking for executable programs, or
(see Library Search) when looking for Lisp files. If
filename is absolute, path has no effect, but the suffixes
in suffixes are still tried.
The optional argument predicate, if non-
nil, specifies a
predicate function for testing whether a candidate file is suitable.
The predicate is passed the candidate file name as its single
argument. If predicate is
nil or omitted,
file-readable-p as the predicate.
See Kinds of Files, for other useful predicates, e.g.,
This function will normally skip directories, so if you want it to
find directories, make sure the predicate function returns
dir-ok for them. For example:
(locate-file "html" '("/var/www" "/srv") nil (lambda (f) (if (file-directory-p f) 'dir-ok)))
For compatibility, predicate can also be one of the symbols
a list of one or more of these symbols.
This function searches for the executable file of the named
program and returns the absolute file name of the executable,
including its file-name extensions, if any. It returns
the file is not found. The function searches in all the directories
exec-path, and tries all the file-name extensions in
exec-suffixes (see Subprocess Creation).
If remote is non-
default-directory is a
remote directory, program is searched on the respective remote host.