批量重命名腳本(Python)


便攜的批處理腳本,代碼如下:

 1 import os
 2 import sys
 3 def rename():
 4     path=input("請輸入路徑(例如D:/picture):")
 5     name=input("請輸入開頭名:")
 6     startNumber=input("請輸入開始數:")
 7     fileType=input("請輸入后綴名(如 .jpg、.txt等等):")
 8     print("正在生成以"+name+startNumber+fileType+"迭代的文件名")
 9     count=0
10     filelist=os.listdir(path)
11     for files in filelist:
12         Olddir=os.path.join(path,files)
13         if os.path.isdir(Olddir):
14             continue
15         Newdir=os.path.join(path,name+str(count+int(startNumber))+fileType)
16         os.rename(Olddir,Newdir)
17         count+=1
18     print("一共修改了"+str(count)+"個文件")
19 
20 rename()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM