We're back after a server migration that caused effbot.org to fall over a bit harder than expected. Expect some glitches.

How do I copy a file?

The shutil module contains functions to copy and move files and directories:

import shutil

shutil.copy(srcfile, dstfile) # copy data and mode bits
shutil.copyfile(srcfile, dstfile) # copy data only
shutil.copytree(srctree, dsttree) # copy directory tree

shutil.move(srcfile, dstfile)
shutil.move(srctree, dsttree)

Note that on MacOS 9, shutil.copy doesn’t copy the resource fork and Finder info. On NTFS file systems, it doesn’t copy file metadata (document summary information). Also, any named streams attached to the file are lost.

For Windows, also see:

how-do-i-copy-a-file-on-windows