- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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'
Advertisements
To Continue Learning Please Login
Login with Google