summaryrefslogtreecommitdiff
path: root/devdocs/elisp/kinds-of-files.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/elisp/kinds-of-files.html')
-rw-r--r--devdocs/elisp/kinds-of-files.html46
1 files changed, 46 insertions, 0 deletions
diff --git a/devdocs/elisp/kinds-of-files.html b/devdocs/elisp/kinds-of-files.html
new file mode 100644
index 00000000..32cb2c17
--- /dev/null
+++ b/devdocs/elisp/kinds-of-files.html
@@ -0,0 +1,46 @@
+ <h4 class="subsection">Distinguishing Kinds of Files</h4> <p>This section describes how to distinguish various kinds of files, such as directories, symbolic links, and ordinary files. </p> <p>Symbolic links are ordinarily followed wherever they appear. For example, to interpret the file name <samp>a/b/c</samp>, any of <samp>a</samp>, <samp>a/b</samp>, and <samp>a/b/c</samp> can be symbolic links that are followed, possibly recursively if the link targets are themselves symbolic links. However, a few functions do not follow symbolic links at the end of a file name (<samp>a/b/c</samp> in this example). Such a function is said to <em>not follow symbolic links</em>. </p> <dl> <dt id="file-symlink-p">Function: <strong>file-symlink-p</strong> <em>filename</em>
+</dt> <dd>
+ <p>If the file <var>filename</var> is a symbolic link, this function does not follow it and instead returns its link target as a string. (The link target string is not necessarily the full absolute file name of the target; determining the full file name that the link points to is nontrivial, see below.) </p> <p>If the file <var>filename</var> is not a symbolic link, or does not exist, or if there is trouble determining whether it is a symbolic link, <code>file-symlink-p</code> returns <code>nil</code>. </p> <p>Here are a few examples of using this function: </p> <div class="example"> <pre class="example">(file-symlink-p "not-a-symlink")
+ ⇒ nil
+</pre>
+<pre class="example">(file-symlink-p "sym-link")
+ ⇒ "not-a-symlink"
+</pre>
+<pre class="example">(file-symlink-p "sym-link2")
+ ⇒ "sym-link"
+</pre>
+<pre class="example">(file-symlink-p "/bin")
+ ⇒ "/pub/bin"
+</pre>
+</div> <p>Note that in the third example, the function returned <samp>sym-link</samp>, but did not proceed to resolve it, although that file is itself a symbolic link. That is because this function does not follow symbolic links—the process of following the symbolic links does not apply to the last component of the file name. </p> <p>The string that this function returns is what is recorded in the symbolic link; it may or may not include any leading directories. This function does <em>not</em> expand the link target to produce a fully-qualified file name, and in particular does not use the leading directories, if any, of the <var>filename</var> argument if the link target is not an absolute file name. Here’s an example: </p> <div class="example"> <pre class="example">(file-symlink-p "/foo/bar/baz")
+ ⇒ "some-file"
+</pre>
+</div> <p>Here, although <samp>/foo/bar/baz</samp> was given as a fully-qualified file name, the result is not, and in fact does not have any leading directories at all. And since <samp>some-file</samp> might itself be a symbolic link, you cannot simply prepend leading directories to it, nor even naively use <code>expand-file-name</code> (see <a href="file-name-expansion">File Name Expansion</a>) to produce its absolute file name. </p> <p>For this reason, this function is seldom useful if you need to determine more than just the fact that a file is or isn’t a symbolic link. If you actually need the file name of the link target, use <code>file-chase-links</code> or <code>file-truename</code>, described in <a href="truenames">Truenames</a>. </p>
+</dd>
+</dl> <dl> <dt id="file-directory-p">Function: <strong>file-directory-p</strong> <em>filename</em>
+</dt> <dd>
+<p>This function returns <code>t</code> if <var>filename</var> is the name of an existing directory. It returns <code>nil</code> if <var>filename</var> does not name a directory, or if there is trouble determining whether it is a directory. This function follows symbolic links. </p> <div class="example"> <pre class="example">(file-directory-p "~rms")
+ ⇒ t
+</pre>
+<pre class="example">(file-directory-p "~rms/lewis/files.texi")
+ ⇒ nil
+</pre>
+<pre class="example">(file-directory-p "~rms/lewis/no-such-file")
+ ⇒ nil
+</pre>
+<pre class="example">(file-directory-p "$HOME")
+ ⇒ nil
+</pre>
+<pre class="example">(file-directory-p
+ (substitute-in-file-name "$HOME"))
+ ⇒ t
+</pre>
+</div> </dd>
+</dl> <dl> <dt id="file-regular-p">Function: <strong>file-regular-p</strong> <em>filename</em>
+</dt> <dd><p>This function returns <code>t</code> if the file <var>filename</var> exists and is a regular file (not a directory, named pipe, terminal, or other I/O device). It returns <code>nil</code> if <var>filename</var> does not exist or is not a regular file, or if there is trouble determining whether it is a regular file. This function follows symbolic links. </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/Kinds-of-Files.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Kinds-of-Files.html</a>
+ </p>
+</div>