Reputation: 187
I have a simple Python 3's script that rename all files in a folder, in the shell it shows the new name applied correctly, but when I go to the folder in windows, the files does not have any extension.
i.e: In python I rename somefile to: "newname.jpg", but on windows it is only "newname", without extension. I guess this is more a Windows 10's problem than a Python's problem.
This is the code:
import os
from os import listdir
i = 0
dir = "./PHOTO GALLERY 1"
for archivo in listdir(dir):
i=i+1
if i<10:
j="0"+str(i)
else:
j=str(i)
print ("Nombre original: " + archivo)
os.rename(dir + "/" + archivo, dir + "/" + "photogallery1_" + j)
print ("Nombre nuevo: " + "photogallery1_" + j + ".jpg")
Upvotes: 0
Views: 77
Reputation: 9690
It looks like you're leaving off the file extension:
os.rename(dir + "/" + archivo, dir + "/" + "photogallery1_" + j)
should be
os.rename(dir + "/" + archivo, dir + "/" + "photogallery1_" + j + ".jpg")
like in your print statement.
Upvotes: 1