all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* emacs lisp command to copy dir and all subdir?
@ 2009-08-25  3:43 Xah Lee
  2009-08-25 15:53 ` notbob
  2009-08-26 12:32 ` Michael Heerdegen
  0 siblings, 2 replies; 11+ messages in thread
From: Xah Lee @ 2009-08-25  3:43 UTC (permalink / raw)
  To: help-gnu-emacs

is there a emacs lisp command to copy a whole dir? like unix's cp -R?

i started to write one:

(defun copy-dir (sourcedir destdir)
  "Copy all files from SOURCEDIR to DESTDIR.

The input dir should not end in a slash.
Example usage:
 (copy-dir
 \"/Users/xah/web/p/um\"
 \"/Users/xah/web/diklo/xx\")

Note: no consideration is taken about links, alias, or file perms."
  (mapc
   (lambda (x)
     (let ()
       (when (and (not (string-equal x ".")) (not (string-equal x
"..")))
         (copy-file
          (concat sourcedir "/" x) destdir) ) ) )
   (directory-files sourcedir) ) )

but it is hackish because of the checking with “.” and “..”,
but also realized this doesn't do sub dirs. In order to do subdir,
it'll prob end up with few hours more...

so, am wondering if there's a pre-made solutions?

Thanks.

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: emacs lisp command to copy dir and all subdir?
  2009-08-25  3:43 emacs lisp command to copy dir and all subdir? Xah Lee
@ 2009-08-25 15:53 ` notbob
  2009-08-26 12:32 ` Michael Heerdegen
  1 sibling, 0 replies; 11+ messages in thread
From: notbob @ 2009-08-25 15:53 UTC (permalink / raw)
  To: help-gnu-emacs

On 2009-08-25, Xah Lee <xahlee@gmail.com> wrote:
> is there a emacs lisp command to copy a whole dir? like unix's cp -R?

> so, am wondering if there's a pre-made solutions?

I'm using emacs 22.3 and it copies recursively by default.  From dired
mode, simply put cursor on dir to be copied and type C (captial C for
copy).  The mini-buffer prompts where to copy to.  If subdirectories
exist, mini-buffer prompts if you want recursive copies (y/n).  I just
tried it and it works fine, which is cool, cuz I sure don't know much
about lisp, yet.  ;)

nb  




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

* Re: emacs lisp command to copy dir and all subdir?
  2009-08-25  3:43 emacs lisp command to copy dir and all subdir? Xah Lee
  2009-08-25 15:53 ` notbob
@ 2009-08-26 12:32 ` Michael Heerdegen
  2009-08-27 15:21   ` Xah Lee
  1 sibling, 1 reply; 11+ messages in thread
From: Michael Heerdegen @ 2009-08-26 12:32 UTC (permalink / raw)
  To: help-gnu-emacs

Have a look at the doc of `dired-recursive-copies'.


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

* Re: emacs lisp command to copy dir and all subdir?
  2009-08-26 12:32 ` Michael Heerdegen
@ 2009-08-27 15:21   ` Xah Lee
  2009-08-28 20:25     ` John A Pershing Jr
  0 siblings, 1 reply; 11+ messages in thread
From: Xah Lee @ 2009-08-27 15:21 UTC (permalink / raw)
  To: help-gnu-emacs

On Aug 26, 5:32 am, Michael Heerdegen <nore...@nospam.dev.null> wrote:
> Have a look at the doc of `dired-recursive-copies'.

sorry all, but a bit clarification.

i needed a copy-dir function for elisp coding, not as user function in
dired.

i haven't thought about looking into how dired-do-copy implement it,
good thought. thanks.

looking into it, it seems a bit complex:

(defun dired-do-copy (&optional arg)
  "Copy all marked (or next ARG) files, or copy the current file.
This normally preserves the last-modified date when copying.
When operating on just the current file, you specify the new name.
When operating on multiple or marked files, you specify a directory,
and new copies of these files are made in that directory
with the same names that the files currently have.  The default
suggested for the target directory depends on the value of
`dired-dwim-target', which see.

This command copies symbolic links by creating new ones,
like `cp -d'."
  (interactive "P")
  (let ((dired-recursive-copies dired-recursive-copies))
    (dired-do-create-files 'copy (function dired-copy-file)
			   "Copy"
			   arg dired-keep-marker-copy
			   nil dired-copy-how-to-fn)))

is this the only way?

i think most modern scripting lang has a copy dir function... that'd
be good in elisp.

 Xah


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

* Re: emacs lisp command to copy dir and all subdir?
  2009-08-27 15:21   ` Xah Lee
@ 2009-08-28 20:25     ` John A Pershing Jr
  2009-09-10 20:23       ` wart
  0 siblings, 1 reply; 11+ messages in thread
From: John A Pershing Jr @ 2009-08-28 20:25 UTC (permalink / raw)
  To: help-gnu-emacs

Xah Lee <xahlee@gmail.com> writes:

> On Aug 26, 5:32 am, Michael Heerdegen <nore...@nospam.dev.null> wrote:
>> Have a look at the doc of `dired-recursive-copies'.
>
> is this the only way?
>
> i think most modern scripting lang has a copy dir function... that'd
> be good in elisp.

Well, you could always run 'cp -p -r ..." in a subshell.

  -jp


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

* Re: emacs lisp command to copy dir and all subdir?
  2009-08-28 20:25     ` John A Pershing Jr
@ 2009-09-10 20:23       ` wart
  2009-09-11 14:16         ` Andreas Politz
       [not found]         ` <mailman.6442.1252678615.2239.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 11+ messages in thread
From: wart @ 2009-09-10 20:23 UTC (permalink / raw)
  To: help-gnu-emacs

I'm with you Xah.  I wish there is such a function.  The reason is
portability.  That way I can run the same elisp code on windows too.



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

* Re: emacs lisp command to copy dir and all subdir?
  2009-09-10 20:23       ` wart
@ 2009-09-11 14:16         ` Andreas Politz
       [not found]         ` <mailman.6442.1252678615.2239.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 11+ messages in thread
From: Andreas Politz @ 2009-09-11 14:16 UTC (permalink / raw)
  To: help-gnu-emacs

wart <fakeid911@gmail.com> writes:

> I'm with you Xah.  I wish there is such a function.  The reason is
> portability.  That way I can run the same elisp code on windows too.

Take a look how dired does it.  Run on your own risk.

(dired-copy-file-recursive "~/.emacs.d/" "/tmp/emacs.d"
                           nil nil nil 'always)

-ap





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

* Re: emacs lisp command to copy dir and all subdir?
       [not found]         ` <mailman.6442.1252678615.2239.help-gnu-emacs@gnu.org>
@ 2009-09-11 17:54           ` Xah Lee
  2009-09-12  1:40             ` Xah Lee
  0 siblings, 1 reply; 11+ messages in thread
From: Xah Lee @ 2009-09-11 17:54 UTC (permalink / raw)
  To: help-gnu-emacs

On Sep 11, 7:16 am, Andreas Politz <poli...@fh-trier.de> wrote:
> wart <fakeid...@gmail.com> writes:
> > I'm with you Xah.  I wish there is such a function.  The reason is
> > portability.  That way I can run the same elisp code on windows too.
>
> Take a look how dired does it.  Run on your own risk.
>
> (dired-copy-file-recursive "~/.emacs.d/" "/tmp/emacs.d"
>                            nil nil nil 'always)

i don't seems to have dired-copy-file-recursive? it doesn't seems to
be in dired.el.

 Xah


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

* Re: emacs lisp command to copy dir and all subdir?
  2009-09-11 17:54           ` Xah Lee
@ 2009-09-12  1:40             ` Xah Lee
  2009-09-12  1:43               ` Xah Lee
  0 siblings, 1 reply; 11+ messages in thread
From: Xah Lee @ 2009-09-12  1:40 UTC (permalink / raw)
  To: help-gnu-emacs

On Sep 11, 7:16 am, Andreas Politz <poli...@fh-trier.de> wrote:
> Take a look how dired does it.  Run on your own risk.
> (dired-copy-file-recursive"~/.emacs.d/" "/tmp/emacs.d"
>  nil nil nil 'always)

On Sep 11, 10:54 am, Xah Lee <xah...@gmail.com> wrote:

> i don't seems to havedired-copy-file-recursive? it doesn't seems to
> be indired.el.

Ok. Found it. Thanks. It is in dired-aux.el.

(require 'dired-aux)
(dired-copy-file-recursive "c:/Users/xah/web/kacma" "c:/Users/xah/web/
kacma2" nil nil nil 'always)

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: emacs lisp command to copy dir and all subdir?
  2009-09-12  1:40             ` Xah Lee
@ 2009-09-12  1:43               ` Xah Lee
  2009-09-12  5:24                 ` Xah Lee
  0 siblings, 1 reply; 11+ messages in thread
From: Xah Lee @ 2009-09-12  1:43 UTC (permalink / raw)
  To: help-gnu-emacs

PS filed a bug report. http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=4408

 Xah

On Sep 11, 6:40 pm, Xah Lee <xah...@gmail.com> wrote:
> On Sep 11, 7:16 am, Andreas Politz <poli...@fh-trier.de> wrote:
>
> > Take a look howdireddoes it.  Run on your own risk.
> > (dired-copy-file-recursive"~/.emacs.d/" "/tmp/emacs.d"
> >  nil nil nil 'always)
>
> On Sep 11, 10:54 am,XahLee <xah...@gmail.com> wrote:
>
> > i don't seems to havedired-copy-file-recursive? it doesn't seems to
> > be indired.el.
>
> Ok. Found it. Thanks. It is indired-aux.el.
>
> (require 'dired-aux)
> (dired-copy-file-recursive"c:/Users/xah/web/kacma" "c:/Users/xah/web/
> kacma2" nil nil nil 'always)
>
>  Xah
> ∑http://xahlee.org/
>
> ☄



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

* Re: emacs lisp command to copy dir and all subdir?
  2009-09-12  1:43               ` Xah Lee
@ 2009-09-12  5:24                 ` Xah Lee
  0 siblings, 0 replies; 11+ messages in thread
From: Xah Lee @ 2009-09-12  5:24 UTC (permalink / raw)
  To: help-gnu-emacs

here's my draft implementation. (thanks for Andreas Politz)

For those who wish to use, here it is. Tested and used for my own
script that used to depend on unix's cp.

(defun copy-directory-recursive (source-dir dest-dir)
  "Copy whole a directory SOURCE-DIR to DEST-DIR.
Note, the semantics of source-dir dest-dir is different from the unix
“cp” utility.
In unix's “cp -R”, if dest-dir exists, it'll copy source-dir itself,
else, just source-dir's children.

In copy-directory-recursive, it always copy source-dir's children.

In both, the dest-dir may or may not exist. If not, it'll be created.
However, dest-dir's parent must exist.

This function is based on dired-copy-file-recursive.
Behavior about linked files, etc, are from that function."
  (require 'dired-aux)
  (dired-copy-file-recursive source-dir dest-dir nil nil nil 'always)
  )

haven't worked on delete-directory-recursive yet...

the unix cp is idiotic...

• Idiocy Of Unix Copy Command
  http://xahlee.org/UnixResource_dir/writ/unix_copy_dir.html

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2009-09-12  5:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-25  3:43 emacs lisp command to copy dir and all subdir? Xah Lee
2009-08-25 15:53 ` notbob
2009-08-26 12:32 ` Michael Heerdegen
2009-08-27 15:21   ` Xah Lee
2009-08-28 20:25     ` John A Pershing Jr
2009-09-10 20:23       ` wart
2009-09-11 14:16         ` Andreas Politz
     [not found]         ` <mailman.6442.1252678615.2239.help-gnu-emacs@gnu.org>
2009-09-11 17:54           ` Xah Lee
2009-09-12  1:40             ` Xah Lee
2009-09-12  1:43               ` Xah Lee
2009-09-12  5:24                 ` Xah Lee

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.