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: