How do I copy a file in Python?
I couldn\'t find anything under os.
copy2(src,dst) is often more useful than copyfile(src,dst) because:
dst
to be a directory (instead of the complete target filename), in which case the basename of src
is used for creating the new file;Here is a short example:
import shutil
shutil.copy2('/src/dir/file.ext', '/dst/dir/newname.ext') # complete target filename given
shutil.copy2('/src/file.ext', '/dst/dir') # target filename is /dst/dir/file.ext