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


Groups > comp.lang.python > #7811

Re: How do you copy files from one location to another?

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 <mail@timgolden.me.uk>
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 <mail@timgolden.me.uk>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.67.1308297884.1164.python-list@python.org> (permalink)
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

Show key headers only | View raw


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:

<code>
import win32file

win32file.MoveFileExW (
   "c:/temp/blah.txt",
   "c:/temp/blah2.txt",
   win32file.MOVEFILE_REPLACE_EXISTING
)

</code>

TJG

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How do you copy files from one location to another? John Salerno <johnjsal@gmail.com> - 2011-06-16 22:06 -0700
  Re: How do you copy files from one location to another? Andrew Berg <bahamutzero8825@gmail.com> - 2011-06-17 01:15 -0500
  Re: How do you copy files from one location to another? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-06-17 19:25 +1200
    Re: How do you copy files from one location to another? John Salerno <johnjsal@gmail.com> - 2011-06-17 09:17 -0700
      Re: How do you copy files from one location to another? Terry Reedy <tjreedy@udel.edu> - 2011-06-17 15:23 -0400
        Re: How do you copy files from one location to another? John Salerno <johnjsal@gmail.com> - 2011-06-17 14:27 -0700
          Re: How do you copy files from one location to another? Ethan Furman <ethan@stoneleaf.us> - 2011-06-17 15:15 -0700
            Re: How do you copy files from one location to another? John Salerno <johnjsal@gmail.com> - 2011-06-17 16:28 -0700
  Re: How do you copy files from one location to another? Tim Golden <mail@timgolden.me.uk> - 2011-06-17 09:04 +0100
  Re: How do you copy files from one location to another? Heather Brown <heather@dejaviewphoto.com> - 2011-06-17 12:43 -0400
  Re: How do you copy files from one location to another? Michael Hrivnak <mhrivnak@hrivnak.org> - 2011-06-18 13:13 -0400
  Re: How do you copy files from one location to another? Terry Reedy <tjreedy@udel.edu> - 2011-06-18 16:52 -0400

csiph-web