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


Groups > comp.lang.python > #7832

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

Date 2011-06-17 12:43 -0400
From Heather Brown <heather@dejaviewphoto.com>
Subject Re: How do you copy files from one location to another?
References <94a80c85-7a66-4de5-ae35-d4a4b0ea7e37@v8g2000yqb.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.78.1308329067.1164.python-list@python.org> (permalink)

Show all headers | View raw


On 01/-10/-28163 02:59 PM, 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.
>

You keep saying 'move' when you want 'copy.'  Even if os.rename would 
work across drives (it doesn't, on Windows), it still would be removing 
the original.  Similarly with move.

As Greg mentioned, you want shutil.copy(), not move nor rename.

DaveA

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