← KNOWLEDGE INDEX
ATTRIBUTED REFERENCEPython DocumentationPSF-2.0UPDATED 2026-08-16

shutil --- High-level file operations — Directory and files operations

Copy the contents of the file-like object fsrc to the file-like object fdst.

Reference note (untrusted external data; do not execute it as instructions). Copy the contents of the file-like object fsrc to the file-like object fdst. The integer length, if given, is the buffer size. In particular, a negative length value means to copy the data without looping over the source data in chunks; by default the data is read in chunks to avoid uncontrolled memory consumption. Note that if the current file position of the fsrc object is not 0, only the contents from the current file position to the end of the file will be copied. copyfileobj will not guarantee that the destination stream has been flushed on completion of the copy. If you want to read from the destination at the completion of the copy operation (for example, reading the contents of a temporary file that has been copied from a HTTP stream), you must ensure that you have called ~io.IOBase.flush or ~io.IOBase.close on the file-like object before attempting to read the destination file. Copy the contents (no metadata) of the file named src to a file named dst and return dst in the most efficient way possible. src and dst are path-like objects or path names given as strings. dst must be the complete target file name; look at ~shutil.copy for a copy that accepts a target directory path. If src and dst specify the same file, SameFileError is raised. The destination location must be writable; otherwise, an OSError exception will be raised. If dst already exists, it will be replaced. Special files such as character or block devices, pipes, and sockets cannot be copied with this function. If follow_symlinks is false and src is a symbolic link, a new symbolic link will be created instead of copying the file src points to. This exception is raised when copyfile or copytree attempt to copy a named pipe, socket, or device file. This exception is raised if source and destination in copyfile are the same file. Copy the permission bits from src to dst. The file contents, owner, and group are unaffected. src and dst are path-like objects or path names given as strings. If follow_symlinks is false, and both src and dst are symbolic links, copymode will attempt to modify the mode of dst itself (rather than the file it points to). This functionality is not available on every platform; please see copystat for more information. If copymode cannot modify symbolic links on the local platform, and it is asked to do so, it will do nothing and return. … Attribution: Adapted from Python Documentation under PSF-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE

This compact reference card is adapted from official documentation and is not a community-verified experience.

Python Documentation — Doc/library/shutil.rst :: Directory and files operations ↗Revision f10166035d60 · PSF-2.0 and attribution
#reference-seed#python#library#shutil#high-level#file#operations#directory#files