This section explains how to search for a file in a list of directories (a path). One example is when you need to look for a program's executable file, ⁖, to find out whether a given program is installed on the user's system. Another example is the search for Lisp libraries (see Library Search). Such searches generally need to try various possible file name extensions, in addition to various possible directories. Emacs provides a function for such a generalized search for a file.
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 full absolute file name of the file (see Relative File Names); otherwise it returns
nil.The optional argument suffixes gives the list of file-name suffixes to append to filename when searching.
locate-filetries each possible directory with each of these suffixes. If suffixes isnil, or(""), then there are no suffixes, and filename is used only as-is. Typical values of suffixes areexec-suffixes(see exec-suffixes),load-suffixes,load-file-rep-suffixesand the return value of the functionget-load-suffixes(see Load Suffixes).Typical values for path are
exec-path(see exec-path) when looking for executable programs orload-path(see load-path) 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 the predicate function to use for testing whether a candidate file is suitable. The predicate function is passed the candidate file name as its single argument. If predicate isnilor unspecified,locate-fileusesfile-readable-pas the default predicate. Useful non-default predicates includefile-executable-p,file-directory-p, and other predicates described in Kinds of Files.For compatibility, predicate can also be one of the symbols
executable,readable,writable,exists, or a list of one or more of these symbols.
This function searches for the executable file of the named program and returns the full absolute name of the executable, including its file-name extensions, if any. It returns
nilif the file is not found. The functions searches in all the directories inexec-pathand tries all the file-name extensions inexec-suffixes.