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?


1 Answer 1


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.

  • I am having trouble omitting __pycache__ directory from dired. Could someone help with the correct regex? I used re-builder but it is not working. May 22, 2021 at 3:06
  • You might want to ask a separate question but "__pycache__\\'" matches anything that ends with __pycache__. If you want to match it exactly, say "\\`__pycache__\\'" and if you want other cases, you can OR it using \\| as above. Do C-h i g (emacs) regexps for more info.
    – NickD
    May 22, 2021 at 3:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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