I'm trying to omit html files from a certain directory when using dired.

For all directories I could do it like so;

(setq dired-omit-files "\\.html$")

I only want to hide html files from my org directory

Here is what didn't work

(setq dired-omit-files "\\/home/map7/org/\\.html$")

Is there a way to do this?


Create a .dir-locals.el file in the directory of interest, with the following contents:

((dired-mode . ((dired-omit-files . "\\.html\\'"))))

If you want to omit the usual suspects as well, then use this regexp (which is the OR of the standard value with the html value above):


Visiting the directory will ask about allowing the local variable which you can accept and enable for future visits with !. Assuming that one way or another, you have enabled dired-omit-mode (e.g. with M-x dired-omit-mode RET), then any .html files are omitted.

To enable dired-omit-mode always, see the doc string for the function: C-h f dired-omit-mode, which says:

To enable omitting in every Dired buffer, you can put this in your init file:

(add-hook 'dired-mode-hook (lambda () (dired-omit-mode)))

This applies to the directory of interest and its subdirectories. I don't know of a way to limit it to just the directory of interest using .dir-locals.el. It might be possible to do it using the more advanced mechanisms that are mentioned in the "Per-directory local variables" section of the manual (which you can get to with C-h i g (emacs)directory variables RET), but I have not gone down that route at all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.