Topic: Python File Copy Program using shutil.filecopy
You can easily copy a source file to a destination file. For this purpose, perform the following steps:
- import shutil module, because the shutil module provides the copyfile() function to copy a source file into a destination file.
- input source file name
- input destination file name
- call shutil.copyfile(sourcefile,destinationfile)
You can see the image number 1 given below which shows the situation before execution of Python File Copy Program. Only one text file named example.txt is shown here on d drive.
Check the image number 2 given below to see the output results of the Python file copying program, in which source file example.txt and destination file example1.txt are in the view.
The complete File Copy Python program is as follows:
Python File Copy Program using shutil
Note that this file copy program has no Exception handling code. Please, read more on exception handling in Python File programs:
You will also like the following Python File Programs:
415 total views, 1 views today