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

 

A Django site. this page was rendered by a django application in 0.02s 2008-10-07 01:50:42.895620. hosted by webfaction.