How to copy file in Python3? Last Updated : 02 Dec, 2020 Comments Improve Suggest changes Like Article Like Report 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)Source Path of File Program: Python3 # copy a file using shutil.copyfile() method import shutil # path where original file is located sourcePath = "c:\\SourceFolder\\gfg.txt" # path were a copy of file is needed destinationPath = "c:\\DestinationFolder\\gfgcopy.txt" # call copyfile() method shutil.copyfile(sourcePath, destinationPath) Output: 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: Data in source file Program: Python3 # open source file in read mode source = open("c:\\SourceFolder\\gfg.txt", "r") # open destination file in write mode dest = open("c:\\DestinationFolder\\gfgcopy.txt", "w") # read first line line = source.readline() # read lines until reached EOF while line: # write line into destination file dest.write(line) # read another line line = source.readline() # close both files source.close() dest.close() Output: Destination File Comment More infoAdvertise with us Next Article How to copy file in Python3? R rohanchopra96 Follow Improve Article Tags : Python python-file-handling Practice Tags : python Similar Reads How to open and close a file in Python There might arise a situation where one needs to interact with external files with Python. Python provides inbuilt functions for creating, writing, and reading files. In this article, we will be discussing how to open an external file and close the same using Python. Opening a file in Python There a 4 min read Python | shutil.copyfile() method Shutil module in Python helps automate the process of copying and removing files and directories. It comes under Pythonâs standard utility modules. Shutil(short for shell utility) module also provides many functions of high-level operations on files and collections of files. What is Shutil.copyfile 4 min read Copy Files and Rename in Python Copying and renaming files is a common task in programming, and Python provides several ways to accomplish this efficiently. In this article, we will explore some commonly used methods for copying files and renaming them: using the shutil module's copy() and pathlib module's Path class. Each method 2 min read Python PIL | copy() method PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. PIL.Image.copy() method copies the image to another image object, this method is useful when we need to copy the image but also retain the original. Syntax:Image.copy() Parameters: no arguments R 1 min read Copy And Replace Files in Python In Python, copying and replacing files is a common task facilitated by modules like `shutil` and `os`. This process involves copying a source file to a destination location while potentially replacing any existing file with the same name. Leveraging functions like `shutil.copy2` and `os.remove`, thi 2 min read Like