Questions tagged [directories]
The directories tag has no usage guidance.
64 questions
49
votes
7
answers
37k
views
Tree-based directory browser?
I love dired, but sometimes (particularly when filming screencasts) I want to see the tree-structure of a directory and its children, a la the tree(1) command. Is there a tree-oriented directory ...
30
votes
4
answers
6k
views
Org Mode link to open directory in Dired
I'd like to have a link like
[[file:~/projects][Projects]]
open directly in Dired rather than Finder (I'm on a Mac), which is what it does now. Is there a way? (Of course there's a way. It's ...
23
votes
2
answers
10k
views
How to check if a directory exists in elisp?
I've seen how to check if a file exists (file-exists-p), but how to check if a directory exists?
16
votes
2
answers
5k
views
Function that returns parent directory absolute path
(parent-dir "/home/sk/parent/ab.el")
gives
"/home/sk/parent"
then,
(parent-dir "/home/sk/parent")
gives
"/home/sk"
Any elisp function as parent-dir that gives basepath for both file path &...
15
votes
5
answers
9k
views
What is the easiest way to open the folder containing the current file by the default explorer of the OS?
What is the easiest way to open the folder containing the current file by the default explorer of the OS (e.g. explorer.exe in the case of Windows OS)?
13
votes
3
answers
3k
views
Recursively go up to find Makefile and compile
The problem with M-x compile is that if the Makefile isn't in the current directory, it fails.
I'd like to have a function that recursively goes up to find a Makefile and run make from this directory....
11
votes
3
answers
3k
views
How can I display the parent directory of the current file in the modeline?
I would like to be able to see the location of the current file's parent directory, independent of the current buffer name.
10
votes
4
answers
1k
views
Opening a new file whose parent directory doesn't exist yet
When opening a new file whose parent directory doesn't exist yet, I either open a shell window, or an Emacs shell buffer, and then mkdir the directory in it. I find this cumbersome. Is there an ...
7
votes
3
answers
3k
views
Expanding Dired to show subdirectories/files?
One of the biggest things I miss from other editors (e.g. Sublime, Intellij) is the ability to see the project structure, and expand/minimize directories as needed so I can see what I care about. Is ...
7
votes
2
answers
468
views
How can I have a second .dir-locals?
When collaborating on a project, certain editing variables are set to
make sure everyone is producing a similar style of code. In Emacs,
these are usually implemented as either file-local variables ...
7
votes
4
answers
2k
views
Quickly jump to favorite folders
What I actually want
I have deep folder structures, and often use a dozen folders pretty far down the directory tree. In Nautilus, I use bookmarks to get to them quickly. I want the same thing in ...
7
votes
4
answers
1k
views
Does some command exist, which goes to the next file of the current directory?
I'm looking for a command inside Emacs.
For example, you are currently in a directory.
In the directory there are 2 files: foo.txt and bar.txt.
I have foo.txt opened in Emacs and is being ...
6
votes
2
answers
330
views
Save all open files in current folder and subfolders
Some of my projects are organised in way that the there isn't one make file at the top route of the project (git/svn/...) folder but I have several small Makefiles in subfolders of the project. ...
6
votes
1
answer
197
views
Nested File Autocompletion in Emacs?
I'm using emacs (technically: spacemacs with helm). It seems that any time I call a function which requires a directory, I am presented with something like the following:
The problem:
If I am in /a/...
4
votes
1
answer
5k
views
How to quickly create a new directory without using dired-mode?
Whenever I've to create a new directory in emacs, I enter dired mode, press "+" and enter the new directory name which creates the new directory.
Is there a way I can avoid using dired-mode and ...
4
votes
2
answers
4k
views
Setting default-directory does not change find-file directory
I try to set a default path for opening a file via C-x C-f by adding the following to my .emacs:
(setq default-directory "~/some_dir/")
However, after I launch Emacs in some directory, the find-file ...
4
votes
2
answers
474
views
How can I recursively delete all empty directories?
That is, if I have
-empty-dir-a/
-nonempty-dir-a/
-empty-dir-a/
-empty-dir-a/
file-a
file-a
file-b
I would like
-nonempty-dir-a/
file-a
file-a
file-b
I'm aware that there are many OS-...
4
votes
1
answer
2k
views
Why/Does Org Mode requires all files in a single org-directory? Why not subfolders?
I am really confused why org mode doesn't accept subfolders. Refiling captures into subfolders doesn't work (doesn't see any files in subfolders). Org agenda doesn't work (same as refiling). Why is it ...
4
votes
1
answer
498
views
Is it possible to do a git clone using Magit in a directory which is not under version control?
Suppose I am in a folder called local-projects. Using the terminal, I can do:
[pedro@system:~/quicklisp/local-projects]$ pwd
/home/pedro/quicklisp/local-projects
An important information to ...
4
votes
0
answers
2k
views
Emacs won’t access Documents directory on MacOS Big Sur
I am running Emacs 26.3 on MacOS 11.2.1 “Big Sur”. When I try to open the directory ~/Documents, it fails with the message “Listing directory failed but ‘access-file’ worked.” Emacs.app is given ...
3
votes
2
answers
404
views
Count number of files with specific extension on a folder?
Let's say I'd like to know how many .png images I have in a folder. In shell I'd run:
ls -1 | grep .png | wc -l
Is there a way to achieve this in emacs (preferably not just reading in from a shell ...
3
votes
1
answer
693
views
How to specify the directory for file-exists/delete-file/byte-compile-file?
I thought it would be great to save a Elisp file (in my init), and it compiles automatically a byte-compile Elisp-file.
So I wrote a function for this.
(defun remove-elc-and-compile-on-save ()
...
3
votes
1
answer
335
views
How can I set the default value for reading a directory name?
I have a folder hardcoded in variable:
(defvar folder-start-mine "/path/to/start/folder/")
Then I want to interactively define new non-existing subfolder name:
(defun my-new-defun (sel-subdir)
...
3
votes
4
answers
969
views
query-replace on directory
How do I search&replace selected instances (in particular those occurring in strings, not in variable names – but using an equivalent of 'query-replace is safer and still fine, there should not be ...
3
votes
1
answer
108
views
Quickly navigate through a cascade of otherwise empty directories in helm
I'd like to be able to quickly skip to the bottom of a cascade of otherwise empty directories. Consider the following directory structure:
foo/
bar/
baz/
a.txt
b.txt
If I were in ...
2
votes
2
answers
994
views
How to make a temporary directory that gets deleted once the body is finished?
Is there a way to temporarily create a new directory, then remove it when the body of the code has finished?
(with-temp-directory path
(write-test-files-into path)
(other-test-functions path))
;...
2
votes
2
answers
426
views
Current directory of Emacs in batch mode
I run Emacs in batch mode to execute some scripting actions. I'd like to get paths of files relative to where Emacs got started in batch mode:
(file-relative-name (buffer-file-name) directory-where-...
2
votes
1
answer
860
views
Can I stop Emacs from resetting default-directory every time I open a file?
If I:
Start Emacs in my home directory (~)
Find a file in the ~/Projects/ruby-play directory with C-x C-f
Try to find another file with C-x C-f
The default directory in the file finder will be ~/...
2
votes
1
answer
165
views
Make emacs aware of updates to files and directories?
In Ubuntu, when I make change to directories or files outside emacs, it seems that emacs doesn't get the update.
For example, C-x C-f can't track the current directory which was just moved elsewhere ...
2
votes
1
answer
610
views
Selecting a directory like counsel-find-file
I would like to write a function that would prompt the user to select a directory, using an UI like that presented by counsel-find-file.
The starting directory should be an arbitrary directory passed ...
2
votes
1
answer
134
views
Converting init file on Mac/Linux to Windows
I use a package called Deft that needs a directory to store and load files. To define this directory on Mac or GNU/Linux I use the following expression:
(setq deft-directory "~/Dropbox/org")
When ...
2
votes
1
answer
385
views
Starting Emacs from a USB stick: how to extract the drive letter assigned to the stick?
I have installed Emacs, with all its init files, on a USB stick for use on different PCs. The init files contains paths to the USB stick itself. The problem is that the drive letter assigned for the ...
2
votes
1
answer
610
views
Function that gets a subdirectory of user-emacs-directory
I remember reading about this function (it's part of Emacs) somewhere, but I can't for the life of me remember what it's called.
It takes a single argument arg (not sure if there's any more optional ...
2
votes
1
answer
228
views
C-x C-f TAB TAB: Find file completion list: how to highlight subdirectories?
Often I'd like to open a file in a subdirectory. But poor me, I can't remember the name. So when typing C-x C-f and then TAB TAB for the completion list, the list of all files in this directory is ...
2
votes
1
answer
724
views
How to quickly jump to a directory in emacs?
Say I have a project directory called "project". In the directory there are two directories "mini1" and "mini2". Suppose my active buffer is deep within a subdirectory in "mini1". Is there a way to ...
1
vote
1
answer
2k
views
Move a file to a directory in the filesystem with emacs lisp
What is the function to move files? I want to emulate the following shell command:
mv file dir
As described here, the closest is rename-file, but this would be emulating this:
mv file newfile
1
vote
1
answer
68
views
What is the difference between contrib/lisp and lisp?
I have both of these folders for my load paths, what is the difference?
~/.emacs.d/contrib/lisp/ vs ~/.emacs.d/lisp/
What should I use one versus the other?
1
vote
2
answers
617
views
How to format org-download's image saving directory(s)?
Suppose following org-file (some_random_name.org) that has 2 images with inserted from org-download.
* heading 1
#+DOWNLOADED: /tmp/xls/xl/media/image2_stage2.png @ 2023-02-24 17:36:38
[[file:...
1
vote
1
answer
313
views
Troubleshooting: changing default folder in .emacs not working
I am trying to make emacs start on the folder where all my orgfiles are saved. I achieved this in my windows machine by changing the "Start In" field of the shortcut properties, as suggested in this ...
1
vote
1
answer
183
views
In DirEd, how can I copy the directory path of a filename?
I have this function
(defun my/dired-copy-dirname-as-kill ()
"Copy the current directory into the kill ring."
(interactive)
(kill-new default-directory))
, but this only copies the ...
1
vote
1
answer
338
views
Open the directory of currently opened file using the OS's file explorer
This is essentially the same question as this one. But the accepted answer there opens Dired for me in Emacs 28 while previously it opened Caja. Could someone offer a fix? I tried commenting there but ...
1
vote
1
answer
177
views
How delete folder named "build" in all subfolders?
Emacs 26.1, Dired+, Windows 10
Suppose I has the next dir tree:
myproject
myproject\app\
myproject\app\build
myproject\app\src
myproject\lib\build
myproject\lib\src
myproject\lib2\build
myproject\...
1
vote
1
answer
73
views
Is there a better way to write this?
I'm walking a directory tree upwards from default-directory in a loop, so I need a way to say "take the last component off this path that ends in a slash and return a result that ends in a slash". The ...
1
vote
1
answer
185
views
Append to exec-path the absolute file names of directories that match a regexp?
As explained here, by
(setq exec-path (append exec-path '("/sw/bin")))
one can append the directory name /sw/bin to exec-path.
Is it possible to append to exec-path the absolute file names of all ...
1
vote
1
answer
328
views
Drag the weblink of a file to a dired folder to save in that folder
Assume that I am visiting a folder (directory) on my system by M-x dired in Emacs. Also assume that I am visiting a webpage like http://www.gnu.org/software/emacs/manual/pdf/ by the default web ...
1
vote
1
answer
70
views
Can I use jump?
I found this package for the bash shell that lets you quickly jump between commonly used folders: https://github.com/gsamokovarov/jump
I use it all the time now.
Jump uses fuzzy matching to find the ...
1
vote
0
answers
58
views
How to get tilde and plus working with the eshell's directory stack
In zsh, when one creates a directory stack with pushd, one is able to reference directories in the stack using a tilde followed by the numerical index of the respective directory in the stack. One ...
1
vote
0
answers
552
views
How to mount/unmount devices?
I'm interested in mounting/umounting usb and other devices directly from emacs.
In many file managers (like nautilus) the devices are automatically discovered and indicated with an icon, it's possible ...
1
vote
1
answer
125
views
Printing a list of folders which has been modified today
Is there any way to export a list of folder names which has been modified today using a dired mode or any other package on emacs
0
votes
4
answers
435
views
How can I save the current Unix working directory in a variable?
I know I can run M-x pwd which will give me Directory ~/ or something like that. Can I get it without the "Directory" bit?
Thank you very much.