

- 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 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 Questions & Answers
- Rename multiple files using Python
- How to rename multiple files recursively using Python?
- How to delete multiple files in a directory in Python?
- Rename multiple files using Java
- How to rename directory using Python?
- How to delete all files in a directory with Python?
- How to copy files to a new directory using Python?
- Rename file or directory in Java
- Java Program to rename a file or directory
- How to copy files into a directory in C#?
- How to find all files in a directory with extension .txt in Python?
- How do I list all files of a directory in Python?
- Python - How to rename multiple column headers in a Pandas DataFrame with Dictionary?
- How can I iterate over files in a given directory in Python?
- How to list all files in a directory using Java?
Advertisements