elisp: Create/Delete Dirs
24.10 Creating, Copying and Deleting Directories
================================================
Most Emacs Lisp file-manipulation functions get errors when used on
files that are directories. For example, you cannot delete a directory
with ‘delete-file’. These special functions exist to create and delete
directories.
-- Command: make-directory dirname &optional parents
This command creates a directory named DIRNAME. If PARENTS is
non-‘nil’, as is always the case in an interactive call, that means
to create the parent directories first, if they don’t already
exist.
‘mkdir’ is an alias for this.
-- Command: copy-directory dirname newname &optional keep-time parents
copy-contents
This command copies the directory named DIRNAME to NEWNAME. If
NEWNAME names an existing directory, DIRNAME will be copied to a
subdirectory there.
It always sets the file modes of the copied files to match the
corresponding original file.
The third argument KEEP-TIME non-‘nil’ means to preserve the
modification time of the copied files. A prefix arg makes
KEEP-TIME non-‘nil’.
The fourth argument PARENTS says whether to create parent
directories if they don’t exist. Interactively, this happens by
default.
The fifth argument COPY-CONTENTS, if non-‘nil’, means to copy the
contents of DIRNAME directly into NEWNAME if the latter is an
existing directory, instead of copying DIRNAME into it as a
subdirectory.
-- Command: delete-directory dirname &optional recursive trash
This command deletes the directory named DIRNAME. The function
‘delete-file’ does not work for files that are directories; you
must use ‘delete-directory’ for them. If RECURSIVE is ‘nil’, and
the directory contains any files, ‘delete-directory’ signals an
error.
‘delete-directory’ only follows symbolic links at the level of
parent directories.
If the optional argument TRASH is non-‘nil’ and the variable
‘delete-by-moving-to-trash’ is non-‘nil’, this command moves the
file into the system Trash instead of deleting it.
Miscellaneous File Operations (emacs)Misc File Ops. When called
interactively, TRASH is ‘t’ if no prefix argument is given, and
‘nil’ otherwise.