

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 do I copy a file in 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 Questions & Answers
- How do I copy a binary file in Python?
- How do I wrap a string in a file in Python?
- How do I check whether a file exists using Python?
- How do I include a php.ini file in another php.ini file?
- How can I source a Python file from another Python file?
- How do I loop through a JSON file with multiple keys/sub-keys in Python?
- How do I create a Python namespace?
- How do I put a jQuery code in an external .js file?
- How do you copy a list in Java?
- How do I do a case insensitive string comparison in Python?
- How do we do a file upload using Python CGI Programming?
- How do I unload (reload) a Python module?
- How do I look inside a Python object?
- How do I create a Java string from the contents of a file?
- How do I create a namespace package in Python?
Advertisements