[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Removing backup files corresponding to no longer existing files
From: |
Deniz Dogan |
Subject: |
Re: Removing backup files corresponding to no longer existing files |
Date: |
Tue, 24 May 2011 22:35:52 +0200 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 |
On 2011-05-08 09:39, Rasmus Villemoes wrote:
> Hi,
>
> I use a couple of separate directories to store emacs backup files
> (using backup-directory-alist). But this means that if I decide to
> delete or move some project (which is in its own direcory), just
> deleting or moving the directory leaves all the backup copies
> behind. They will then stay in the backup directories forever.
>
> Is there a way to tell emacs to remove backup files which no longer
> correspond to an actual file?
>
> It's probably not very difficult to write a little (shell/perl) script
> to do this, but I was wondering if there is some builtin way which
> I've overlooked.
>
> Emacs 23.1.1 on Ubuntu 10.10, if it matters.
>
> Thanks in advance,
> Rasmus
I'm a bit late to the party, but I wrote this Emacs Lisp function which
should do what you want:
(defun delete-old-backups (directory)
(interactive "DDirectory: ")
(let ((files (directory-files directory t)))
(dolist (pair backup-directory-alist)
(dolist (file files)
(when (string-match (car pair) file)
(delete-file (expand-file-name file (cdr pair))))))))
As I don't make use of `backup-directory-alist' myself, I cannot test it
easily.
You can do this in a slightly different way as well, passing the MATCH
argument to `directory-files' instead of getting all of the files in
that directory and checking the regexps afterwards.
Hope that helps!
Deniz