M-x all-things-emacs

Quick Tip: dired-recursive-deletes

February 8th, 2007 by Ryan McGeary · 7 Comments

By default, dired only deletes empty directories. You know the drill. Put your point on the directory, D, y (yes), “file-error Removing directory directory not empty,” (slam fist on table). Doh!

Fortunately, dired supports deleting directories recursively. Add this to your .emacs:

(setq dired-recursive-deletes 'top)

The dired-recursive-deletes variable decides whether recursive deletes are allowed. This particular setting will prompt with confirmation for each directory at the top level but delete all subdirectories without asking. Other possible values include:

  • nil means no recursive deletes. (default)
  • 'top means ask for each directory at the top level but delete subdirectories without asking.
  • 'always means delete recursively without asking. Warning: The Surgeon General has determined that this may be hazardous to your health.
  • Anything else means ask for each directory (including subdirectories).

As always, C-h v dired-recursive-deletes for the full low-down.

Tags: dired · quick · tips

7 responses so far ↓

  • 1 elmarco // Feb 23, 2007 at 9:50 am

    OMG! thanks :)

  • 2 nazir // Mar 13, 2007 at 8:52 am

    Thanks!!

  • 3 ma82 // Dec 22, 2007 at 4:25 pm

    I was looking for a solution to ‘file-error’ right now (after carefully choosing a long list of files and directories…), and I found yours in less than a second!

    Thanks a lot! :-)

  • 4 John B├Ąckstrand // Jan 28, 2010 at 10:02 am

    I’d like it to ask just once, not for every top-level directory since I often delete 6-7 directories. I really just want one question about that, not 6-7!

    :(

  • 5 Ryan McGeary // Jan 29, 2010 at 4:13 pm

    John, Then you should set dired-recursive-deletes to 'top.

  • 6 rtra // May 23, 2010 at 8:09 am

    I think ‘always is what john wants.

  • 7 malcolm cook // Jun 26, 2012 at 8:30 pm

    I was just prompted to write this:

    http://malcook-gedanken.blogspot.com/2012/06/get-more-aggressive-control-over-emac.html