This program uses the
shutil.copy2() function to copy the file. The
shutil.copy2() function is similar to the
shutil.copy() function, but also preserves additional metadata such as the file’s modification and access times. The
dst_file variables specify the source file path and the destination file path, respectively. Note that the path separator is ‘\’ for Windows.
Here is an example Python program that copies a file from one location to another on a Windows machine, using the same file name:
import shutil # specify the source file path and destination file path src_file = 'C:\\path\\to\\source\\file.txt' dst_file = 'C:\\path\\to\\destination\\file.txt' # copy the file shutil.copy2(src_file, dst_file)