1 New in the picture folder py Script rename.py
import os
# Want to change the root directory where the picture is located
rootdir="./"
# Get the list of file names in the directory
files=os.listdir(rootdir)
# Process each file name in the file name list
for filename in files:
portion=os.path.splitext(filename) #portion Separate the list of names and suffixes #os.path.splitext() Separate the file name from the extension
if portion[1]==".bmp": # If tiff Then change the name
newname=portion[0]+".jpg" # New suffix to be changed # A new name
print(filename) # Print out the file name you want to change
os.chdir(rootdir) # Modify the work path
os.rename(filename,newname) # Rename the file name under the working path
2 stay cmd Window run rename.py
Input cmd open windows
rename.py
perhaps
python rename.py
Successful transformation
If it is Shift+ Right click The open powershell Window
python rename.py