i need to rename a multiple files from a folder with numbers increament in python.i.e. First file in a folder gets renamed with 1 and second file get a name with 2.like that..How to solve this
Asked
Active
Viewed 83 times
1 Answers
0
You should first iterate through files in a directory, and the rename the files.
It might look like this:
import os
# Let's say you want to rename files in the current directory
index = 1
for filename in os.listdir(os.getcwd()):
os.rename(filename, '_'.join([str(index),filename]))
index += 1
This can be the approach and then you should adapt it to your needs.