
- 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 copy certain files from one folder to another 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.
example
import shutil, os files = ['file1.txt', 'file2.txt', 'file3.txt'] for f in files: shutil.copy(f, 'dest_folder')
- Related Articles
- How to copy files from one folder to another using Python?
- How to copy files from one server to another using Python?
- How to move a file from one folder to another using Python?
- How can I copy a file from one folder to another folder within a container in Docker?
- How to Copy files or Folder without overwriting existing files?
- How to copy items from one location to another location using PowerShell?
- How we can copy Python modules from one system to another?
- How to copy Docker images from one host to another without using a repository?
- How to copy files to a new directory using Python?
- How to copy a table from one MySQL database to another?
- How to copy rows from one table to another in MySQL?
- How to read multiple text files from a folder in Python?(Tkinter)
- How to copy the palette from one image to another using imagepalettecopy() function in PHP?
- How to copy a collection from one database to another in MongoDB?
- Copy values from one array to another in Numpy

Advertisements