M-x all-things-emacs

Quick Tip: dired-recursive-deletes

February 8th, 2007 by Ryan McGeary · 3 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

3 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! :-)

Leave a Comment