summaryrefslogtreecommitdiff
path: root/devdocs/elisp/contents-of-directories.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/elisp/contents-of-directories.html
new repository
Diffstat (limited to 'devdocs/elisp/contents-of-directories.html')
-rw-r--r--devdocs/elisp/contents-of-directories.html45
1 files changed, 45 insertions, 0 deletions
diff --git a/devdocs/elisp/contents-of-directories.html b/devdocs/elisp/contents-of-directories.html
new file mode 100644
index 00000000..e0511901
--- /dev/null
+++ b/devdocs/elisp/contents-of-directories.html
@@ -0,0 +1,45 @@
+ <h3 class="section">Contents of Directories</h3> <p>A directory is a kind of file that contains other files entered under various names. Directories are a feature of the file system. </p> <p>Emacs can list the names of the files in a directory as a Lisp list, or display the names in a buffer using the <code>ls</code> shell command. In the latter case, it can optionally display information about each file, depending on the options passed to the <code>ls</code> command. </p> <dl> <dt id="directory-files">Function: <strong>directory-files</strong> <em>directory &amp;optional full-name match-regexp nosort count</em>
+</dt> <dd>
+<p>This function returns a list of the names of the files in the directory <var>directory</var>. By default, the list is in alphabetical order. </p> <p>If <var>full-name</var> is non-<code>nil</code>, the function returns the files’ absolute file names. Otherwise, it returns the names relative to the specified directory. </p> <p>If <var>match-regexp</var> is non-<code>nil</code>, this function returns only those file names whose non-directory part contain a match for that regular expression—the other file names are excluded from the list. On case-insensitive filesystems, the regular expression matching is case-insensitive. </p> <p>If <var>nosort</var> is non-<code>nil</code>, <code>directory-files</code> does not sort the list, so you get the file names in no particular order. Use this if you want the utmost possible speed and don’t care what order the files are processed in. If the order of processing is visible to the user, then the user will probably be happier if you do sort the names. </p> <p>If <var>count</var> is non-<code>nil</code>, the function will return names of first <var>count</var> number of files, or names of all files, whichever occurs first. <var>count</var> has to be an integer greater than zero. </p> <div class="example"> <pre class="example">(directory-files "~lewis")
+ ⇒ ("#foo#" "#foo.el#" "." ".."
+ "dired-mods.el" "files.texi"
+ "files.texi.~1~")
+</pre>
+</div> <p>An error is signaled if <var>directory</var> is not the name of a directory that can be read. </p>
+</dd>
+</dl> <dl> <dt id="directory-empty-p">Function: <strong>directory-empty-p</strong> <em>directory</em>
+</dt> <dd>
+<p>This utility function returns <code>t</code> if given <var>directory</var> is an accessible directory and it does not contain any files, i.e., is an empty directory. It will ignore ‘<samp>.</samp>’ and ‘<samp>..</samp>’ on systems that return them as files in a directory. </p> <p>Symbolic links to directories count as directories. See <var>file-symlink-p</var> to distinguish symlinks. </p>
+</dd>
+</dl> <dl> <dt id="directory-files-recursively">Function: <strong>directory-files-recursively</strong> <em>directory regexp &amp;optional include-directories predicate follow-symlinks</em>
+</dt> <dd>
+<p>Return all files under <var>directory</var> whose names match <var>regexp</var>. This function searches the specified <var>directory</var> and its sub-directories, recursively, for files whose basenames (i.e., without the leading directories) match the specified <var>regexp</var>, and returns a list of the absolute file names of the matching files (see <a href="relative-file-names">absolute file names</a>). The file names are returned in depth-first order, meaning that files in some sub-directory are returned before the files in its parent directory. In addition, matching files found in each subdirectory are sorted alphabetically by their basenames. By default, directories whose names match <var>regexp</var> are omitted from the list, but if the optional argument <var>include-directories</var> is non-<code>nil</code>, they are included. </p> <p>By default, all subdirectories are descended into. If <var>predicate</var> is <code>t</code>, errors when trying to descend into a subdirectory (for instance, if it’s not readable by this user) are ignored. If it’s neither <code>nil</code> nor <code>t</code>, it should be a function that takes one parameter (the subdirectory name) and should return non-<code>nil</code> if the directory is to be descended into. </p> <p>Symbolic links to subdirectories are not followed by default, but if <var>follow-symlinks</var> is non-<code>nil</code>, they are followed. </p>
+</dd>
+</dl> <dl> <dt id="locate-dominating-file">Function: <strong>locate-dominating-file</strong> <em>file name</em>
+</dt> <dd>
+<p>Starting at <var>file</var>, go up the directory tree hierarchy looking for the first directory where <var>name</var>, a string, exists, and return that directory. If <var>file</var> is a file, its directory will serve as the starting point for the search; otherwise <var>file</var> should be a directory from which to start. The function looks in the starting directory, then in its parent, then in its parent’s parent, etc., until it either finds a directory with <var>name</var> or reaches the root directory of the filesystem without finding <var>name</var> – in the latter case the function returns <code>nil</code>. </p> <p>The argument <code>name</code> can also be a predicate function. The predicate is called for every directory examined by the function, starting from <var>file</var> (even if <var>file</var> is not a directory). It is called with one argument (the file or directory) and should return non-<code>nil</code> if that directory is the one it is looking for. </p>
+</dd>
+</dl> <dl> <dt id="directory-files-and-attributes">Function: <strong>directory-files-and-attributes</strong> <em>directory &amp;optional full-name match-regexp nosort id-format count</em>
+</dt> <dd><p>This is similar to <code>directory-files</code> in deciding which files to report on and how to report their names. However, instead of returning a list of file names, it returns for each file a list <code>(<var>filename</var> . <var>attributes</var>)</code>, where <var>attributes</var> is what <code>file-attributes</code> returns for that file. The optional argument <var>id-format</var> has the same meaning as the corresponding argument to <code>file-attributes</code> (see <a href="file-attributes#Definition-of-file_002dattributes">Definition of file-attributes</a>). </p></dd>
+</dl> <dl> <dt id="directory-files-no-dot-files-regexp">Constant: <strong>directory-files-no-dot-files-regexp</strong>
+</dt> <dd>
+<p>This regular expression matches any file name except ‘<samp>.</samp>’ and ‘<samp>..</samp>’. More precisely, it matches parts of any nonempty string except those two. It is useful as the <var>match-regexp</var> argument to <code>directory-files</code> and <code>directory-files-and-attributes</code>: </p> <div class="example"> <pre class="example">(directory-files "/foo" nil directory-files-no-dot-files-regexp)
+</pre>
+</div> <p>returns <code>nil</code>, if directory ‘<samp>/foo</samp>’ is empty. </p>
+</dd>
+</dl> <dl> <dt id="file-expand-wildcards">Function: <strong>file-expand-wildcards</strong> <em>pattern &amp;optional full</em>
+</dt> <dd>
+<p>This function expands the wildcard pattern <var>pattern</var>, returning a list of file names that match it. </p> <p>If <var>pattern</var> is written as an absolute file name, the values are absolute also. </p> <p>If <var>pattern</var> is written as a relative file name, it is interpreted relative to the current default directory. The file names returned are normally also relative to the current default directory. However, if <var>full</var> is non-<code>nil</code>, they are absolute. </p>
+</dd>
+</dl> <dl> <dt id="insert-directory">Function: <strong>insert-directory</strong> <em>file switches &amp;optional wildcard full-directory-p</em>
+</dt> <dd>
+<p>This function inserts (in the current buffer) a directory listing for directory <var>file</var>, formatted with <code>ls</code> according to <var>switches</var>. It leaves point after the inserted text. <var>switches</var> may be a string of options, or a list of strings representing individual options. </p> <p>The argument <var>file</var> may be either a directory or a file specification including wildcard characters. If <var>wildcard</var> is non-<code>nil</code>, that means treat <var>file</var> as a file specification with wildcards. </p> <p>If <var>full-directory-p</var> is non-<code>nil</code>, that means the directory listing is expected to show the full contents of a directory. You should specify <code>t</code> when <var>file</var> is a directory and switches do not contain ‘<samp>-d</samp>’. (The ‘<samp>-d</samp>’ option to <code>ls</code> says to describe a directory itself as a file, rather than showing its contents.) </p> <p>On most systems, this function works by running a directory listing program whose name is in the variable <code>insert-directory-program</code>. If <var>wildcard</var> is non-<code>nil</code>, it also runs the shell specified by <code>shell-file-name</code>, to expand the wildcards. </p> <p>MS-DOS and MS-Windows systems usually lack the standard Unix program <code>ls</code>, so this function emulates the standard Unix program <code>ls</code> with Lisp code. </p> <p>As a technical detail, when <var>switches</var> contains the long ‘<samp>--dired</samp>’ option, <code>insert-directory</code> treats it specially, for the sake of dired. However, the normally equivalent short ‘<samp>-D</samp>’ option is just passed on to <code>insert-directory-program</code>, as any other option. </p>
+</dd>
+</dl> <dl> <dt id="insert-directory-program">Variable: <strong>insert-directory-program</strong>
+</dt> <dd><p>This variable’s value is the program to run to generate a directory listing for the function <code>insert-directory</code>. It is ignored on systems which generate the listing with Lisp code. </p></dd>
+</dl><div class="_attribution">
+ <p class="_attribution-p">
+ Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
+ <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Contents-of-Directories.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Contents-of-Directories.html</a>
+ </p>
+</div>