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

Python renames multiple images

編輯:Python

adopt python Language , Rename multiple images .

# -*- coding:utf8 -*-
import os
# Image file path 
path = 'C:\\Users\\Administrator\\Desktop\\122'
# Absolute path 
filelist = os.listdir(path)
i = 10
# Only for picture naming methods starting with numbers 
for item in filelist:
#print('item name is ',item)
if item.endswith('.png'):
# The first picture is named 1.png
i = i + 1
# Only by converting numbers to strings can they be named 
name = str(i)
# The path of the original image 
src = os.path.join(os.path.abspath(path),item)
# Target image path 
dst = os.path.join(os.path.abspath(path),'tufen.'+name + '.png')
try:
os.rename(src,dst)
# Print the conversion result on the terminal for inspection 
print('rename from %s to %s'%(src,dst))
except:
continue

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