diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/elisp/directory-names.html | |
new repository
Diffstat (limited to 'devdocs/elisp/directory-names.html')
| -rw-r--r-- | devdocs/elisp/directory-names.html | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/devdocs/elisp/directory-names.html b/devdocs/elisp/directory-names.html new file mode 100644 index 00000000..d6fc941f --- /dev/null +++ b/devdocs/elisp/directory-names.html @@ -0,0 +1,31 @@ + <h4 class="subsection">Directory Names</h4> <p>A <em>directory name</em> is a string that must name a directory if it names any file at all. A directory is actually a kind of file, and it has a file name (called the <em>directory file name</em>), which is related to the directory name but is typically not identical. (This is not quite the same as the usual POSIX terminology.) These two names for the same entity are related by a syntactic transformation. On GNU and other POSIX-like systems, this is simple: to obtain a directory name, append a ‘<samp>/</samp>’ to a directory file name that does not already end in ‘<samp>/</samp>’. On MS-DOS the relationship is more complicated. </p> <p>The difference between a directory name and a directory file name is subtle but crucial. When an Emacs variable or function argument is described as being a directory name, a directory file name is not acceptable. When <code>file-name-directory</code> returns a string, that is always a directory name. </p> <p>The following two functions convert between directory names and directory file names. They do nothing special with environment variable substitutions such as ‘<samp>$HOME</samp>’, and the constructs ‘<samp>~</samp>’, ‘<samp>.</samp>’ and ‘<samp>..</samp>’. </p> <dl> <dt id="file-name-as-directory">Function: <strong>file-name-as-directory</strong> <em>filename</em> +</dt> <dd> +<p>This function returns a string representing <var>filename</var> in a form that the operating system will interpret as the name of a directory (a directory name). On most systems, this means appending a slash to the string (if it does not already end in one). </p> <div class="example"> <pre class="example">(file-name-as-directory "~rms/lewis") + ⇒ "~rms/lewis/" +</pre> +</div> </dd> +</dl> <dl> <dt id="directory-name-p">Function: <strong>directory-name-p</strong> <em>filename</em> +</dt> <dd><p>This function returns non-<code>nil</code> if <var>filename</var> ends with a directory separator character. This is the forward slash ‘<samp>/</samp>’ on GNU and other POSIX-like systems; MS-Windows and MS-DOS recognize both the forward slash and the backslash ‘<samp>\</samp>’ as directory separators. </p></dd> +</dl> <dl> <dt id="directory-file-name">Function: <strong>directory-file-name</strong> <em>dirname</em> +</dt> <dd> +<p>This function returns a string representing <var>dirname</var> in a form that the operating system will interpret as the name of a file (a directory file name). On most systems, this means removing the final directory separators from the string, unless the string consists entirely of directory separators. </p> <div class="example"> <pre class="example">(directory-file-name "~lewis/") + ⇒ "~lewis" +</pre> +</div> </dd> +</dl> <dl> <dt id="file-name-concat">Function: <strong>file-name-concat</strong> <em>directory &rest components</em> +</dt> <dd> +<p>Concatenate <var>components</var> to <var>directory</var>, inserting a slash before the components if <var>directory</var> or the preceding component didn’t end with a slash. </p> <div class="example"> <pre class="example">(file-name-concat "/tmp" "foo") + ⇒ "/tmp/foo" +</pre> +</div> <p>A <var>directory</var> or components that are <code>nil</code> or the empty string are ignored—they are filtered out first and do not affect the results in any way. </p> <p>This is almost the same as using <code>concat</code>, but <var>dirname</var> (and the non-final components) may or may not end with slash characters, and this function will not double those characters. </p> +</dd> +</dl> <p>To convert a directory name to its abbreviation, use this function: </p> <dl> <dt id="abbreviate-file-name">Function: <strong>abbreviate-file-name</strong> <em>filename</em> +</dt> <dd> +<p>This function returns an abbreviated form of <var>filename</var>. It applies the abbreviations specified in <code>directory-abbrev-alist</code> (see <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/File-Aliases.html#File-Aliases">File Aliases</a> in <cite>The GNU Emacs Manual</cite>), then substitutes ‘<samp>~</samp>’ for the user’s home directory if the argument names a file in the home directory or one of its subdirectories. If the home directory is a root directory, it is not replaced with ‘<samp>~</samp>’, because this does not make the result shorter on many systems. </p> <p>You can use this function for directory names and for file names, because it recognizes abbreviations even as part of the name. </p> +</dd> +</dl><div class="_attribution"> + <p class="_attribution-p"> + Copyright © 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/Directory-Names.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Directory-Names.html</a> + </p> +</div> |
