程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python: batch modify the suffix of pictures

編輯:Python

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


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved