How do you copy files from one location to another?

Terry Reedy tjreedy at udel.edu
Fri Jun 17 15:23:01 EDT 2011


On 6/17/2011 12:17 PM, John Salerno wrote:
> On Jun 17, 2:25 am, Gregory Ewing<greg.ew... at canterbury.ac.nz>  wrote:

>> It sounds like shutil.copy() is what you want, or one of the
>> other related functions in the shutil module.

> This looks promising! But can src be a directory, or does it have to
> be a file? For my purposes (copying a saved games folder), I don't
> really need to specify particular files to copy, I just need to copy
> the entire Saved Games directory, so that's what would be my src
> argument if allowed.

If you follow the second part of Greg's suggestion 'or one of the other 
related function in the shutil module', you will find copytree()
"Recursively copy an entire directory tree rooted at src. "
>
> Also, the directory I want to copy also contains a directory. Will the
> contents of that directory also be copied, or do I have to do some
> kind of walk-through of the directory manually?

If you want more control of which files to copy, between 1 and all, look 
as os.walk and the glob module.

-- 
Terry Jan Reedy




More information about the Python-list mailing list