[Tutor] simple copy within a python script

Brad Chandler mbc2@netdoor.com
Wed, 25 Oct 2000 12:09:19 -0500


> Writing a python script to find a string in a file and replace it with
> another.  But before I manipulate the file I want to make a copy of the
> file.  How within the python script can I do this?  Working on a Unix
> platform.

If you just want to make a duplicate of the file, you can import the shutil
module and use the following:

shutil.copy2(frompath,topath)

The shutil.copy2 will retain the original access, modified, etc.. dates
whereas the shutil.copy will change all of those.

Brad Chandler