Elisp: File and Directory Functions
Here's the most useful functions for file and directory.
Functions on File
rename-file-
(rename-file FILE NEWNAME &optional OK-IF-ALREADY-EXISTS)rename or move file
(rename-file "~/test1.txt" "~/test2.txt") ;; move file ;; second arg must be a dir, must end in slash (rename-file "~/test1.txt" "~/.emacs.d/temp/") copy-file-
(copy-file FILE NEWNAME &optional OK-IF-ALREADY-EXISTS KEEP-TIME PRESERVE-UID-GID PRESERVE-PERMISSIONS)copy file
(copy-file "~/test1.txt" "~/test2.txt") ;; copy file to a dir ;; second arg must be a dir, must end in slash (copy-file "~/test1.txt" "~/.emacs.d/temp/") delete-file-
(delete-file "~/test2.txt")
make-empty-fileset-file-modes
Create Temp File
make-temp-file-
(make-temp-file PREFIX &optional DIR-FLAG SUFFIX TEXT)create temp file or dir with unique name at
temporary-file-directory, and optionally with content.
temporary-file-directory-
return the path of temp file dir of the operating system
Functions on Directory
directory-files-
List files. 〔see Elisp: Walk Directory, List Files〕
make-directory-
Create a directory.
delete-directory-
Delete a whole dir.
new in Emacs 23 (date 2009-07)
(delete-directory "~/stuff" t) copy-directory-
(copy-directory "~/stuff" "~/stuff-backup") directory-empty-p-
new in Emacs 28 (date 2022)
other. unsorted
these are less used.
- Variable: inhibit-file-name-operation
- Function:
find-file-name-handler - Function:
file-local-copy - Function:
file-remote-p - Function:
unhandled-file-name-directory - Function:
file-local-name - User Option: remote-file-name-inhibit-cache
- Variable: format-alist
- Variable: buffer-file-format
- Command:
format-write-file - Command:
format-find-file - Command:
format-insert-file - Variable: buffer-auto-save-file-format
- Variable: write-region-annotate-functions
- Variable: write-region-post-annotation-function
- Variable: after-insert-file-functions
file-chase-linksfile-equal-pfile-name-case-insensitive-pvc-responsible-backend
file-newer-than-file-pfile-has-changed-pfile-attributesfile-nlinks
file-aclfile-selinux-contextfile-extended-attributes
locate-fileexecutable-find
Reference
Elisp, File, Buffer
- Elisp: Buffer Functions
- Elisp: Read File
- Elisp: Read File Content as String or Lines
- Elisp: Write File
- Elisp: Open File, Read, Possibly Write
- Elisp: File and Directory Functions
- Elisp: Get File Info
- Elisp: File Path Functions
- Elisp: Walk Directory, List Files
- Elisp: Walk Directory by Depth 📜
- Elisp: Get Dired Marked Files