Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'raised': 0.07; 'from:addr:timgolden.me.uk': 0.09; 'from:name:tim golden': 0.09; 'message-id:@timgolden.me.uk': 0.09; 'overwrite': 0.09; 'pywin32': 0.09; 'rename': 0.09; 'subject:files': 0.09; 'syntax.': 0.09; 'this:': 0.10; 'wrote:': 0.14; '"on': 0.16; 'dst': 0.16; 'exposes': 0.16; 'oserror': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'subject:copy': 0.16; 'cc:addr:python-list': 0.17; 'this?': 0.19; 'header:In-Reply- To:1': 0.21; 'seems': 0.21; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'index': 0.25; 'function': 0.25; 'mainly': 0.26; 'says': 0.27; 'script': 0.27; "i'm": 0.27; 'subject:?': 0.29; 'import': 0.29; 'subject:How': 0.30; 'cc:addr:python.org': 0.30; 'module': 0.30; 'confused': 0.30; 'exist.': 0.30; 'exists,': 0.30; 'tjg': 0.30; 'it.': 0.31; "can't": 0.32; 'skip:" 20': 0.33; "i've": 0.33; 'file': 0.34; 'header:User-Agent:1': 0.35; 'skip:" 10': 0.35; 'another': 0.37; 'could': 0.38; 'subject:from': 0.38; 'run': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'received:192': 0.38; 'read,': 0.40; 'delete': 0.40; 'john': 0.62; 'back': 0.63; 'from:addr:mail': 0.65; 'subject:one': 0.77; 'subject:you': 0.80; 'drive.': 0.91; 'to:none': 0.93 Date: Fri, 17 Jun 2011 09:04:34 +0100 From: Tim Golden User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 CC: python-list@python.org Subject: Re: How do you copy files from one location to another? References: <94a80c85-7a66-4de5-ae35-d4a4b0ea7e37@v8g2000yqb.googlegroups.com> In-Reply-To: <94a80c85-7a66-4de5-ae35-d4a4b0ea7e37@v8g2000yqb.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308297884 news.xs4all.nl 49047 [::ffff:82.94.164.166]:43598 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7811 On 17/06/2011 06:06, John Salerno wrote: > Based on what I've read, it seems os.rename is the proper function to > use, but I'm a little confused about the syntax. Basically I just want > to write a simple script that will back up my saved game files when I > run it. So I want it to copy a set of files/directories from a > location on my C:\ drive to another directory on my E:\ drive. I don't > want to rename or delete the originals, just move them. I also want > them to automatically overwrite whatever already happens to be in the > location on the E:\ drive. > > Is os.rename the proper function for this? Mainly I was because the > Module Index says this: > > "On Windows, if dst already exists, OSError will be raised even if it > is a file.." > > so it sounds like I can't move the files to a location where those > file names already exist. For a Windows-only Q&D, you could use the pywin32 win32file module which exposes the MoveFileEx[W] API: import win32file win32file.MoveFileExW ( "c:/temp/blah.txt", "c:/temp/blah2.txt", win32file.MOVEFILE_REPLACE_EXISTING ) TJG