Languages
[Edit]
EN

Python - copy file example

0 points
Created by:
crystal
382

In this article, we would like to show you how to copy file in Python.

Quick solution:

import shutil

shutil.copyfile(source_path, destination_path)

 

Practical example

In this example, we use copyfile() method from shutil package to copy example.txt file.

import shutil

shutil.copyfile("C:\\some_path\example_directory\example.txt",
                "C:\\some_path\example_directory\example_copy.txt")

Result:

Python - copy file - before
Python - copy file - before
Python - copy file - after
Python - copy file - after

Note:

If the file under destination_path already exist it will be replaced.

Python - file operations

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join