Languages
[Edit]
EN

Python - copy file example

0 points
Created by:
crystal
572

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.

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

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