问题来源
弄着博客时候,找个很多好看的图片,然后先给他们起个名字好上传到图床,自己改太累了,索性弄个 Python 改
程序
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| import os import re import sys
fileList = os.listdir(r"C:\Users\10074\Desktop\picdiet") print("修改前:" + str(fileList))
currentpath = os.getcwd()
os.chdir(r"C:\Users\10074\Desktop\picdiet")
num = 1
for fileName in fileList: pat = ".+\.(jpg)" pattern = re.findall(pat, fileName) os.rename(fileName, ("post" + str(num) + '.' + pattern[0])) num = num + 1
os.chdir(currentpath)
sys.stdin.flush()
print("修改后:" + str(os.listdir(r"C:\Users\10074\Desktop\picdiet")))
|