File copy functions in shutil
Helpful utility functions in the shutil module of the standard library for copying files.
-
copyfile(src, dst, *, follow_symlinks=True)bothsrcanddstcan be eitherstror a path like object (for example,pathlib.Path).dstneeds to be a file path, not a destination directory. Only copies file content, does not copy metadata. -
shutil.copy(src, dst, *, follow_symlinks=True)bothsrcanddstcan be eitherstror a path like object (for example,pathlib.Path).dstcan be either a file path or the destination directory. Returns the path to the newly created file. Copies data and permissions, but does not copy other metadata like file creation and modification times. If you want to preserve all metadata useshutil.copy2(src, dst, *, follow_symlinks=True)