
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
How to create a duplicate file of an existing file using Python?
The shutil module provides functions for copying files, as well as entire folders.
Calling shutil.copy(source, destination) will copy the file at the path source to the folder at the path destination. (Both source and destination are strings.) If destination is a filename, it will be used as the new name of the copied file. This function returns a string of the path of the copied file. For example,
>>> import shutil >>> # Copy the file in same folder with different name >>> shutil.copy('original.txt', 'duplicate.txt') '/home/username/duplicate.txt' >>> shutil.copy('original.txt', 'my_folder/duplicate.txt') '/home/username/my_folder/duplicate.txt'
- Related Articles
- How to create an empty file using Python?
- How to create hardlink of a file using Python?
- How to create softlink of a file using Python?
- How to create a tar file using Python?
- How to create a zip file using Python?
- How to add/append content to an existing file using Java?
- How to create a unique temporary file name using Python?
- Python Pandas- Create multiple CSV files from existing CSV file
- C# Program to make a copy of an existing file
- How to create a File Chooser using JavaFX?
- How to create a temporary file using PowerShell?
- Check whether the given file is an existing file in Java
- How to create Python objects based on an XML file?
- Golang program to append a string in an existing file
- Java Program to Append Text to an Existing File

Advertisements