VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-copy-file-in-python3/

⇱ How to copy file in Python3? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to copy file in Python3?

Last Updated : 23 Jul, 2025

Prerequisites: Shutil

When we require a backup of data, we usually make a copy of that file. Python supports file handling and allows users to handle files i.e., to read and write files, along with many other file handling options, to operate on files. Here we will learn how to copy a file using Python3.

Method 1 : Using shutil library

shutil library includes a method call copyfile(). The method takes two parameters, one is source path of file and other is destination path of file. The following image includes a file with its path.

Syntax:

copyfile(source_path,destination_path)
👁 Image
Source Path of File

Program:

Output:

👁 Image
Destination Folder

Method 2 : copying data of file into another file

Copying data of one file to another file could also create a backup of file. Suppose the data of file is as below:

👁 Image
Data in source file

Program:

Output:

👁 Image
Destination File
Comment
Article Tags: