
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to rename multiple files in a directory in Python?
If you have a list of files you want to rename and corresponding new file name, You can use os module's rename method.
For example
import os for old, new in files.iteritems(): # files.items() in Python 3 os.rename(old, new)
You can also use the shutil (or shell utilities) module. Calling shutil.move(source, destination) will move the file or folder at the path source to the path destination and will return a string of the absolute path of the new location.
For example
import shutil for old, new in files.iteritems(): # files.items() in Python 3 shutil.move(old, new)
- Related Articles
- How to delete multiple files in a directory in Python?
- How to rename multiple files recursively using Python?
- Rename multiple files using Python
- How to rename directory using Python?
- Rename multiple files using Java
- How to delete all files in a directory with Python?
- How to copy files to a new directory using Python?
- How to find all files in a directory with extension .txt in Python?
- Python - How to rename multiple column headers in a Pandas DataFrame with Dictionary?
- How do I list all files of a directory in Python?
- How can I iterate over files in a given directory in Python?
- How to copy files into a directory in C#?
- Rename file or directory in Java
- Java Program to rename a file or directory
- How to list all files in a directory using Java?

Advertisements