How do you copy files from one location to another?
Heather Brown
heather at dejaviewphoto.com
Fri Jun 17 12:43:58 EDT 2011
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
More information about the Python-list
mailing list