emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* function for cleaning org-attach directories
@ 2015-07-16  8:57 Eric Abrahamsen
  2015-07-16  9:38 ` Alan Schmitt
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Abrahamsen @ 2015-07-16  8:57 UTC (permalink / raw)
  To: emacs-orgmode

I use org-attach a lot, and if you're not careful you can get a "data/"
directory of many gigabytes. Not a problem, until you want to rsync it
and it takes all day...

I wrote this to clean my attach directories. I'm not sure how portable
it is (and I'm really not pleased with the (concat attach-dir "/" d "/"
d+)), but I'm posting it to see if it's useful to anyone.

Comments/improvements welcome! If the final product is desirable, I can
work it up as a patch.

Eric

(defun org-attach-clean-dirs (&optional attach-dir clean-archived)
  (interactive)
  (let ((attach-dir
	 (if attach-dir
	     (file-name-as-directory attach-dir)
	   (concat (file-name-as-directory org-directory)
		   org-attach-directory)))
	(valid-dir-re "\\`[0-9a-z-]+\\'")
	(org-id-search-archives (if clean-archived nil org-id-search-archives)))
    (dolist (d (directory-files attach-dir nil valid-dir-re))
      (dolist (d+ (directory-files
		   (concat attach-dir d) nil valid-dir-re))
	(let ((id (format "%s%s" d d+))
	      (full-path (concat attach-dir "/" d "/" d+)))
	  (unless (org-id-find id)
	    (shell-command (format "rm -fr %s" full-path))))))))

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-08-01  9:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-16  8:57 function for cleaning org-attach directories Eric Abrahamsen
2015-07-16  9:38 ` Alan Schmitt
2015-07-16 12:43   ` Eric Abrahamsen
2015-07-17  5:19     ` Eric Abrahamsen
2015-07-17 15:01       ` Alan Schmitt
2015-07-18  3:11         ` Eric Abrahamsen
2015-07-20 15:04           ` Alan Schmitt
2015-08-01  9:23             ` [PATCH] " Eric Abrahamsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).