Python File Copy Program using shutil.filecopy

By | April 1, 2020

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:

  1. import shutil module, because the shutil module provides the copyfile() function to copy a source file into a destination file.
  2. input source file name
  3. input destination file name
  4. 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.

"<yoastmark

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.

"<yoastmark

The complete File Copy Python program is as follows:

Python File Copy Program using shutil

import shutil

source=input("Enter source file name and path:\n")
dest=input("Enter destination file name and path:\n")

s=shutil.copyfile(source,dest)
print(" The file ' " +source +"  '  copied to '" + s + " ' successfully")

Note that this file copy program has no Exception handling code. Please, read more on exception handling in Python File programs:

Python Exception Handling FileNotFoundError

You will also like the following Python File Programs:

Loading

2 thoughts on “Python File Copy Program using shutil.filecopy

  1. Pingback: Python Text File Program To Count Vowels | EasyCodeBook.com

  2. Pingback: Python File Phonebook Program | EasyCodeBook.com

Leave a Reply

Your email address will not be published. Required fields are marked *