comparison lispref/files.texi @ 62585:78962e585d20

(Locating Files): New subsection. Describe locate-file and executable-find.
author Eli Zaretskii <eliz@gnu.org>
date Sat, 21 May 2005 13:30:24 +0000
parents d0cfb9c978f9
children 19deaa395e85 5b029ff3b08d
comparison
equal deleted inserted replaced
62584:f8cc1658963a 62585:78962e585d20
733 733
734 @node Information about Files 734 @node Information about Files
735 @section Information about Files 735 @section Information about Files
736 736
737 The functions described in this section all operate on strings that 737 The functions described in this section all operate on strings that
738 designate file names. All the functions have names that begin with the 738 designate file names. With a few exceptions, all the functions have
739 word @samp{file}. These functions all return information about actual 739 names that begin with the word @samp{file}. These functions all
740 files or directories, so their arguments must all exist as actual files 740 return information about actual files or directories, so their
741 or directories unless otherwise noted. 741 arguments must all exist as actual files or directories unless
742 otherwise noted.
742 743
743 @menu 744 @menu
744 * Testing Accessibility:: Is a given file readable? Writable? 745 * Testing Accessibility:: Is a given file readable? Writable?
745 * Kinds of Files:: Is it a directory? A symbolic link? 746 * Kinds of Files:: Is it a directory? A symbolic link?
746 * Truenames:: Eliminating symbolic links from a file name. 747 * Truenames:: Eliminating symbolic links from a file name.
747 * File Attributes:: How large is it? Any other names? Etc. 748 * File Attributes:: How large is it? Any other names? Etc.
749 * Locating Files:: How to find a file in standard places.
748 @end menu 750 @end menu
749 751
750 @node Testing Accessibility 752 @node Testing Accessibility
751 @comment node-name, next, previous, up 753 @comment node-name, next, previous, up
752 @subsection Testing Accessibility 754 @subsection Testing Accessibility
1251 has an inode number of 129500. 1253 has an inode number of 129500.
1252 @item -32252 1254 @item -32252
1253 is on file system number -32252. 1255 is on file system number -32252.
1254 @end table 1256 @end table
1255 @end defun 1257 @end defun
1258
1259 @node Locating Files
1260 @subsection How to Locate Files in Standard Places
1261 @cindex locate files
1262 @cindex find files
1263
1264 Sometimes, you need to find a file that could reside in one of the
1265 standard directories. One example is when you need to look for a
1266 program's executable file, e.g., to find out whether a given program
1267 is installed on the user's system. Another example is the search for
1268 Lisp libraries (@pxref{Library Search}). Such searches generally need
1269 to try several alternative file name extensions, in addition to
1270 looking in every standard directory where the file could be found.
1271 Emacs provides a function for such a generalized search for a file.
1272
1273 @defun locate-file filename path &optional suffixes predicate
1274 This function searches for the file whose name is @var{filename} in
1275 a list of directories given by @var{path}. If it finds the file, it
1276 returns its full @dfn{absolute file name} (@pxref{Relative File
1277 Names}); if the file is not found, the function returns @code{nil}.
1278
1279 The optional argument @var{suffixes} gives the list of file-name
1280 suffixes to append to @var{filename} when searching. If
1281 @var{suffixes} is @code{nil}, it's equivalent to passing a list with a
1282 single element that is an empty string @code{""}.
1283
1284 Typical values of @var{path} are @code{exec-path} (@pxref{Subprocess
1285 Creation, exec-path}) when looking for executable programs or
1286 @code{load-path} (@pxref{Library Search, load-path}) when looking for
1287 Lisp files. Use @code{("/")} to disable the path search (e.g., if
1288 @var{filename} already includes the leading directories), but still
1289 try the extensions in @var{suffixes}.
1290
1291 Typical values of @var{suffixes} are @code{exec-suffixes}
1292 (@pxref{Subprocess Creation, exec-suffixes}) and @code{load-suffixes}
1293 (@pxref{Library Search, load-suffixes}).
1294
1295 The optional argument @var{predicate}, if non-@code{nil}, specifies
1296 the predicate function to use for testing whether a candidate file is
1297 suitable. The predicate function is passed the candidate file name as
1298 its single argument. If @var{predicate} is @code{nil} or unspecified,
1299 @code{locate-file} uses @code{file-readable-p} as the default
1300 predicate. Useful non-default predicates include
1301 @code{file-executable-p}, @code{file-directory-p}, and other
1302 predicates described in @ref{Kinds of Files}.
1303
1304 For compatibility, @var{predicate} can also be one of the symbols
1305 @code{executable}, @code{readable}, @code{writable}, @code{exists}, or
1306 a list of one or more of these symbols.
1307 @end defun
1308
1309 @cindex find executable program
1310 @defun executable-find program
1311 This function searches for the executable file of the named
1312 @var{program} and returns the full absolute name of the executable,
1313 including its file-name extensions, if any. It returns @code{nil} if
1314 the file is not found. The functions searches in all the directories
1315 in @code{exec-path} and tries all the file-name extensions in
1316 @code{exec-suffixes}.
1317 @end defun
1318
1256 1319
1257 @node Changing Files 1320 @node Changing Files
1258 @section Changing File Names and Attributes 1321 @section Changing File Names and Attributes
1259 @cindex renaming files 1322 @cindex renaming files
1260 @cindex copying files 1323 @cindex copying files