[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

25.6.5 How to Locate Files in Standard Places

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, e.g., to find out whether a given program is installed on the user's system. Another example is the search for Lisp libraries (voir la section 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.

Function: locate-file filename path &optional suffixes predicate

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 (voir la section Absolute and 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-file tries each possible directory with each of these suffixes. If suffixes is nil, or (""), then there are no suffixes, and filename is used only as-is. Typical values of suffixes are exec-suffixes (voir la section exec-suffixes), load-suffixes, load-file-rep-suffixes and the return value of the function get-load-suffixes (voir la section Load Suffixes).

Typical values for path are exec-path (voir la section exec-path) when looking for executable programs or load-path (voir la section 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 is nil or unspecified, locate-file uses file-readable-p as the default predicate. Useful non-default predicates include file-executable-p, file-directory-p, and other predicates described in Distinguishing 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.

Function: executable-find program

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 nil if the file is not found. The functions searches in all the directories in exec-path and tries all the file-name extensions in exec-suffixes.


[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

Ce document a été généré par Eric Reinbold le 13 Octobre 2007 en utilisant texi2html 1.78.