The copy method of the shutil module
The copy method of the shutil module copies a file while preserving its access mode. The first parameter of the method specifies the path to the source file, and the second parameter specifies the destination path of the new file.
The third optional parameter specifies how to work with symbolic links (by default follow_symlinks=True).
Syntax
import shutil
shutil.copy(where do we copy from, where do we copy to, [mode for symbolic links])
Example
Let's copy the file file1.txt to the file file2.txt:
import shutil
shutil.copy('file1.txt', 'file2.txt')
See also
-
method
copy2of moduleshutil,
which copies a file with metadata -
method
copytreeof moduleshutil,
which recursively copies a folder -
method
path.isfileof moduleos,
which checks the existence of a file -
method
moveof moduleshutil,
which recursively moves a file or directory -
method
makedirsof moduleos,
which creates folders -
method
mkdirof moduleos,
which creates one folder -
method
rmdirof moduleos,
which moves or deletes an empty folder -
method
removeof moduleos,
which deletes the file -
method
getcwdmoduleos,
which returns the current working directory