Skip to main content
Share Your Experience: Take the 2024 Developer Survey
36 votes
Accepted

How to check if a directory exists in elisp?

From elisp manual: -- Function: file-directory-p filename This function returns ‘t’ if FILENAME is the name of an existing directory, ‘nil’ otherwise. See also its docstring, with a note ...
JeanPierre's user avatar
  • 7,475
19 votes

Tree-based directory browser?

Have you ever tried Emacs' M-x speedbar? :-) before installing some new package I'd try an inbuilt solution... Update 2020-01-10 Actually I'm using now dired-sidebar which is available via Melpa.
Dieter.Wilhelm's user avatar
15 votes

How to check if a directory exists in elisp?

file-directory-p is your friend. Found using C-u C-h a directory RET and browsing the result.
Harald Hanche-Olsen's user avatar
11 votes

Expanding Dired to show subdirectories/files?

In Dired you can include a subdirectory using i, with the cursor on the subdir line. You can do likewise on a subdir line within a subdir listing, so you can list any number of levels of any number ...
Drew's user avatar
  • 77.9k
8 votes
Accepted

How to quickly create a new directory without using dired-mode?

You could use M-x make-directory DIRNAME RET. The default path is the path to the current buffer folder. You could bind it to key (like C-x C-f) with (global-set-key (kbd "C-c d") 'make-directory). ...
Konstantin Morenko's user avatar
7 votes
Accepted

Count number of files with specific extension on a folder?

(length (directory-files "~/Pictures" nil "\\.png\\'")) See C-hf directory-files
phils's user avatar
  • 51.6k
7 votes
Accepted

Quickly jump to favorite folders

It's unclear to me why you want/need to add such symlinks. Why not just use Emacs bookmarks? If you use Bookmark+ then you can have: Bookmarks to Dired buffers (which record lots of stuff, including ...
Drew's user avatar
  • 77.9k
6 votes
Accepted

How to make a temporary directory that gets deleted once the body is finished?

make-temp-file can be used to make a directory instead of a file, this example simply calls make-temp-file, then removes the directory afterwards. (let ((temp-dir (make-temp-file "foo" t))) (unwind-...
xo6xu's user avatar
  • 76
5 votes

Move a file to a directory in the filesystem with emacs lisp

That function can actually move files to directories, but its documentation was not in accord with its features. If the destination ends in a /, then the file is moved. e.g. (rename-file "foo" "bar/")...
rpluim's user avatar
  • 5,325
5 votes
Accepted

Current directory of Emacs in batch mode

You can use command-line-default-directory, it is intended when using Emacs in batch mode, or when processing command line options: Default directory to use for command line arguments. This is ...
Lindydancer's user avatar
  • 6,170
4 votes

Expanding Dired to show subdirectories/files?

dired-subtree is an option and looks as follows: If using use-package, you can enable in your init.el and bind to TAB and SHIFT-TAB with: (use-package dired-subtree :ensure t :after dired :...
Alvaro's user avatar
  • 106
4 votes
Accepted

How can I have a second .dir-locals?

As of I think version 26.1, Emacs does support a second additional .dir-locals.el file (aptly named .dir-locals-2.el). From the Emacs Manual: "Per-Directory Local Variables": You can also use .dir-...
ebpa's user avatar
  • 7,499
3 votes
Accepted

Starting Emacs from a USB stick: how to extract the drive letter assigned to the stick?

If you use Dired+ then you can use command diredp-w32-list-mapped-drives, to list your current MS Windows drives. If you want to roll your own, just use shell command net use. This is all there is to ...
Drew's user avatar
  • 77.9k
3 votes
Accepted

Troubleshooting: changing default folder in .emacs not working

According to https://superuser.com/a/478766/770454, one must disable startup-screen: (setq inhibit-startup-screen t) I think that the default welcome screen with the links to the tutorial etc, ...
Picaud Vincent's user avatar
3 votes

Tree-based directory browser?

Treemacs works. It allows you to have a treelike structure.
decabytes's user avatar
  • 147
3 votes

How to make a temporary directory that gets deleted once the body is finished?

;; Inspired from `dired-create-directory` code. (defun with-temp-dir (dir) "..." (let* ((expanded (directory-file-name (expand-file-name dir))) (try expanded) new) (...
Drew's user avatar
  • 77.9k
3 votes
Accepted

Converting init file on Mac/Linux to Windows

No. Emacs on MS Windows uses the GNU/Unix conventions of ~ and / as directory separator, just fine. See also the Emacs manual, nodes Minibuffer File and Windows HOME. (And on MS Windows be sure to ...
Drew's user avatar
  • 77.9k
3 votes

Selecting a directory like counsel-find-file

I just figured this out myself (using counsel-dired as a model): (defun my-counsel-find-directory (&optional start-dir) "Return a directory chosen by the user. The user is prompted to ...
izkon's user avatar
  • 1,878
2 votes

Org Mode link to open directory in Dired

If you don't mind writing/executing lisp code you could do: [[elisp: (find-file "~/projects")][Projects]] This is what I do. Maybe there are other possibilities if you check the manual ...
programingfrik's user avatar
2 votes

What is the easiest way to open the folder containing the current file by the default explorer of the OS?

(defun open-this-buffer-directory-on-windows() (interactive) (shell-command "explorer .") )
dianyuluo's user avatar
2 votes

What is the easiest way to open the folder containing the current file by the default explorer of the OS?

Run shell-command (M+!) with the default explorer program and the current folder, e.g. for MS Windows, explorer .
estownya's user avatar
  • 303
2 votes

Expanding Dired to show subdirectories/files?

http://cedet.sourceforge.net/speedbar.shtml Speedbar is an Emacs Lisp program which allows you to create a special skinny frame with a specialized directory listing in it. This listing will have ...
Low Powah's user avatar
  • 317
2 votes

Nested File Autocompletion in Emacs?

You can use package helm-locate while searching by issuing C-u C-x C-f. This will, however, search globally. If you are in a Git repository you can also do helm-ls-git-ls with C-x C-d, searching in ...
theldoria's user avatar
  • 1,845
2 votes

Is there a better way to write this?

You say, "take the last component off [a] path that ends in a slash and return a result that ends in a slash". Is this what you're looking for? This is from Dired+ (but it doesn't depend on anything ...
Drew's user avatar
  • 77.9k
2 votes

Quickly jump to favorite folders

Emacs has built-in bookmark functionnality, bound to C-x r b. If you install Helm you get helm-bookmarks, an interactive and colorful version, that lets you jump to one or set a bookmark in the same ...
Ehvince's user avatar
  • 1,091
2 votes
Accepted

How can I set the default value for reading a directory name?

The built-in support for prompting a user for a directory name, via the G flag as you have used, does not support setting the default directory. You can do this explicitly with a lisp expression ...
Tyler's user avatar
  • 22.4k
2 votes

How delete folder named "build" in all subfolders?

In Dired: You can use D (command dired-do-delete) to delete all marked files and subdirectories in the current Dired listing You can use M-+ D (command diredp-do-delete-recursive) to delete all ...
Drew's user avatar
  • 77.9k
2 votes
Accepted

Open the directory of currently opened file using the OS's file explorer

Probably a better alternative (for which I have defined a command in my dotfile) to the answer in the comments, because it does not open a process buffer, is: (let ((process-connection-type nil)) ...
dalanicolai's user avatar
  • 7,865
2 votes
Accepted

Is it possible to do a git clone using Magit in a directory which is not under version control?

I think the problem is that you are doing magit-status, presumably so you can use the C binding to do the clone. But the doc for magit-status says: If the current directory isn’t located within a Git ...
NickD's user avatar
  • 30.6k

Only top scored, non community-wiki answers of a minimum length are eligible