- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 copy files to a new directory using Python?
The shutil module provides functions for copying files, as well as entire folders. For copying multiple files at once, you'll have to have a list of all files you want to copy and loop over them to copy them.
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, os files = ['file1.txt', 'file2.txt', 'file3.txt'] os.mkdir('my_new_folder') for f in files: shutil.copy(f, 'my_new_folder')
- Related Articles
- How to copy files into a directory in C#?
- How to copy a file, group of files, or directory in Linux?
- How to copy files from one folder to another using Python?
- How to copy files from one server to another using Python?
- How to copy multiple files in PowerShell using Copy-Item?
- How to copy certain files from one folder to another using Python?
- How to merge multiple files into a new file using Python?
- How to concatenate two files into a new file using Python?
- How to list all files in a directory using Java?
- How to rename multiple files in a directory in Python?
- How to delete multiple files in a directory in Python?
- How to delete all files in a directory with Python?
- How to list all files (only) from a directory using Java?
- How to read data from all files in a directory using Java?
- How to copy files of the specific extension using PowerShell?

Advertisements