summaryrefslogtreecommitdiff
path: root/devdocs/elisp/relative-file-names.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/elisp/relative-file-names.html')
-rw-r--r--devdocs/elisp/relative-file-names.html29
1 files changed, 29 insertions, 0 deletions
diff --git a/devdocs/elisp/relative-file-names.html b/devdocs/elisp/relative-file-names.html
new file mode 100644
index 00000000..ca1a5b26
--- /dev/null
+++ b/devdocs/elisp/relative-file-names.html
@@ -0,0 +1,29 @@
+ <h4 class="subsection">Absolute and Relative File Names</h4> <p>All the directories in the file system form a tree starting at the root directory. A file name can specify all the directory names starting from the root of the tree; then it is called an <em>absolute</em> file name. Or it can specify the position of the file in the tree relative to a default directory; then it is called a <em>relative</em> file name. On GNU and other POSIX-like systems, after any leading ‘<samp>~</samp>’ has been expanded, an absolute file name starts with a ‘<samp>/</samp>’ (see <a href="directory-names#abbreviate_002dfile_002dname">abbreviate-file-name</a>), and a relative one does not. On MS-DOS and MS-Windows, an absolute file name starts with a slash or a backslash, or with a drive specification ‘<samp><var>x</var>:/</samp>’, where <var>x</var> is the <em>drive letter</em>. </p> <dl> <dt id="file-name-absolute-p">Function: <strong>file-name-absolute-p</strong> <em>filename</em>
+</dt> <dd>
+<p>This function returns <code>t</code> if file <var>filename</var> is an absolute file name, <code>nil</code> otherwise. A file name is considered to be absolute if its first component is ‘<samp>~</samp>’, or is ‘<samp>~<var>user</var></samp>’ where <var>user</var> is a valid login name. In the following examples, assume that there is a user named ‘<samp>rms</samp>’ but no user named ‘<samp>nosuchuser</samp>’. </p> <div class="example"> <pre class="example">(file-name-absolute-p "~rms/foo")
+ ⇒ t
+</pre>
+<pre class="example">(file-name-absolute-p "~nosuchuser/foo")
+ ⇒ nil
+</pre>
+<pre class="example">(file-name-absolute-p "rms/foo")
+ ⇒ nil
+</pre>
+<pre class="example">(file-name-absolute-p "/user/rms/foo")
+ ⇒ t
+</pre>
+</div> </dd>
+</dl> <p>Given a possibly relative file name, you can expand any leading ‘<samp>~</samp>’ and convert the result to an absolute name using <code>expand-file-name</code> (see <a href="file-name-expansion">File Name Expansion</a>). This function converts absolute file names to relative names: </p> <dl> <dt id="file-relative-name">Function: <strong>file-relative-name</strong> <em>filename &amp;optional directory</em>
+</dt> <dd>
+<p>This function tries to return a relative name that is equivalent to <var>filename</var>, assuming the result will be interpreted relative to <var>directory</var> (an absolute directory name or directory file name). If <var>directory</var> is omitted or <code>nil</code>, it defaults to the current buffer’s default directory. </p> <p>On some operating systems, an absolute file name begins with a device name. On such systems, <var>filename</var> has no relative equivalent based on <var>directory</var> if they start with two different device names. In this case, <code>file-relative-name</code> returns <var>filename</var> in absolute form. </p> <div class="example"> <pre class="example">(file-relative-name "/foo/bar" "/foo/")
+ ⇒ "bar"
+(file-relative-name "/foo/bar" "/hack/")
+ ⇒ "../foo/bar"
+</pre>
+</div> </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/Relative-File-Names.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Relative-File-Names.html</a>
+ </p>
+</div>