Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Cameron Simpson Newsgroups: comp.lang.python Subject: Re: real usable file/directory operation module? Date: Fri, 11 Dec 2015 14:43:25 +1100 Lines: 32 Message-ID: References: Reply-To: python-list@python.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed X-Trace: news.uni-berlin.de d2bXgdSH1wk3sPAeMFHyPgM1wG3u9oAgozJcRJftA7jA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'paths': 0.05; 'shutil': 0.07; 'subject:file': 0.07; 'cc:addr:python-list': 0.09; 'already.': 0.09; 'command.': 0.09; 'compute': 0.09; 'overwrite': 0.09; 'situation.': 0.09; 'subject:module': 0.09; 'suggest': 0.15; 'intermediate': 0.15; '"d",': 0.16; '"destination': 0.16; "'%s'": 0.16; "'d',": 0.16; '(write': 0.16; 'exists"': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'os.walk': 0.16; 'oyster': 0.16; 'real_dst': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'simpson': 0.16; 'wrote:': 0.16; 'module,': 0.18; 'tree': 0.18; 'windows': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'cheers,': 0.22; 'fit': 0.23; 'matching': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'example': 0.26; 'command': 0.26; '(which': 0.26; 'consult': 0.27; '"no': 0.29; 'another.': 0.29; 'btw,': 0.29; 'invoke': 0.29; 'raise': 0.29; 'subject:/': 0.30; 'entry': 0.31; 'source': 0.33; 'directory,': 0.33; 'surely': 0.33; 'newer': 0.35; 'path': 0.35; 'something': 0.35; 'supports': 0.35; 'but': 0.36; 'instead': 0.36; 'there': 0.36; 'data.': 0.36; 'mode': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'missing': 0.37; 'charset:us-ascii': 0.37; 'manual': 0.38; 'received:localdomain': 0.38; 'files': 0.38; 'easy': 0.60; 'your': 0.60; 'cameron': 0.66; 'offer': 0.66; 'header:Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'own)': 0.84; 'reply- to:addr:python.org': 0.84; 'route': 0.84; 'directories,': 0.91 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100251 On 11Dec2015 11:04, oyster 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