Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100251 > unrolled thread

Re: real usable file/directory operation module?

Started byCameron Simpson <cs@zip.com.au>
First post2015-12-11 14:43 +1100
Last post2015-12-11 14:43 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: real usable file/directory operation module? Cameron Simpson <cs@zip.com.au> - 2015-12-11 14:43 +1100

#100251 — Re: real usable file/directory operation module?

FromCameron Simpson <cs@zip.com.au>
Date2015-12-11 14:43 +1100
SubjectRe: real usable file/directory operation module?
Message-ID<mailman.127.1449805414.12405.python-list@python.org>
On 11Dec2015 11:04, oyster <lepto.python@gmail.com> wrote:
>there is shutil module, but I find it limits the user heavily. For
>example, I want to move 2 directories "a/scene" and "c/scene" to "d",
>but there is "scene" under d already. Then shutil.move will raise
>Error, "Destination path '%s' already exists" % real_dst
>
>So is there any module, which allow me move/copy like Windows does.
>for example
>useableShutil.move('a/scene', 'd', overwite=True)

Surely the "subprocess" module, which would let you invoke the Windows copy 
command.

The reason that the stdlib doesn't offer something like that is that there are 
many many decisions one might make when overlaying one directory tree on 
another. Consult the manual entry for rsync to get a feel for how many nuances 
one might want in such a situation. The Window's "copy" command makes one set 
of choices; they may not fit many users' needs.

Instead the stdlib supports the simple "no conflicts" case (which is safe) and 
leaves it to others to solve harder problems, because there are many ways to 
"solve" those problems.

It is very easy to invoke os.walk on the "copying in" tree and compute the 
matching paths in the target directory, and then make your own decisions (make 
missing intermediate directories, overwrite existing files or only if the 
source is newer or whatever). BTW, if you go this route (write your own) then I 
suggest you give it a "no action" mode to report what it will do - that way you 
can check first before destroying your data.

Cheers,
Cameron Simpson <cs@zip.com.au>

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web