emacs-devel
[Top][All Lists]
Advanced

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

Re: bug in copy-directory


From: Thierry Volpiatto
Subject: Re: bug in copy-directory
Date: Fri, 11 Feb 2011 09:12:47 +0100
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.2.93 (gnu/linux)

Stefan Monnier <address@hidden> writes:

>> In the shell, of course, you just do "cp -r /foo/* /bar".  That's
>> because cp acts on both files and directories; copy-directory only
>> copies directories.  This implies that giving copy-directory cp-like
>> semantics might be a mistake.
>
> OK.
If you want to keep the ability to do "cp -r /foo/* /bar" you can just
add a new arg copy-contents-only (or whatever name) to copy-directory:


--8<---------------cut here---------------start------------->8---
(defun copy-directory (directory newname &optional keep-time parents 
copy-contents-only)

[...]

            (unless copy-contents-only
              (setq newname (expand-file-name
                             (file-name-nondirectory
                              (directory-file-name directory))
                             newname))
              (and (file-exists-p newname)
                   (not (file-directory-p newname))
                   (error "Cannot overwrite non-directory %s with a directory"
                          newname))
              (make-directory newname t)))


[...]
--8<---------------cut here---------------end--------------->8---


and do:

(copy-directory "/foo" "/existing/directory/bar" nil nil t)

NOTE: 
- this feature would not work with tramp names without changes to
  tramp.
  However (copy-directory "/foo" "/existing/directory/bar")
  will work without changes.


-- 
A+ Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 




reply via email to

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