emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Re: Org-attach for a directory


From: Ihor Radchenko
Subject: [PATCH] Re: Org-attach for a directory
Date: Thu, 09 Jun 2022 17:37:53 +0800

Cletip Cletip <clement020302@gmail.com> writes:

> Thank you for your answer.
> Unfortunately, I would like to copy the entire directory.
> To clarify my second question, I would like to have a folder system with
> org-mode, and therefore only use org-attach to store my documents

Note that it makes much more sense to use 'mv method when you actually
use attachments as your filesystem. There is no need to keep trailing
garbage files. 'mv methods works for directories.

As for the 'cp method, it does not work for directories on current main.
The fix is attached.

Best,
Ihor

>From 6d879aeca5d1c52a824df998704298d9ee4a4a0a Mon Sep 17 00:00:00 2001
Message-Id: 
<6d879aeca5d1c52a824df998704298d9ee4a4a0a.1654767374.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Thu, 9 Jun 2022 17:33:49 +0800
Subject: [PATCH] org-attach-attach: Allow attaching directories using 'cp
 method

* lisp/org-attach.el (org-attach-attach): Use `copy-directory' when
FILE is a directory.  Remove trailing slash before processing.
---
 lisp/org-attach.el | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index 5ee2b84b2..00919bef8 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -517,12 +517,17 @@ (defun org-attach-attach (file &optional visit-dir method)
     current-prefix-arg
     nil))
   (setq method (or method org-attach-method))
+  (when (file-directory-p file)
+    (setq file (directory-file-name file)))
   (let ((basename (file-name-nondirectory file)))
     (let* ((attach-dir (org-attach-dir 'get-create))
            (attach-file (expand-file-name basename attach-dir)))
       (cond
        ((eq method 'mv) (rename-file file attach-file))
-       ((eq method 'cp) (copy-file file attach-file))
+       ((eq method 'cp)
+        (if (file-directory-p file)
+            (copy-directory file attach-file nil nil t)
+          (copy-file file attach-file)))
        ((eq method 'ln) (add-name-to-file file attach-file))
        ((eq method 'lns) (make-symbolic-link file attach-file))
        ((eq method 'url) (url-copy-file file attach-file)))
-- 
2.35.1


reply via email to

[Prev in Thread] Current Thread [Next in Thread]