python批量修改文件名(去掉部分字符串)


 1 import os
 2 path = "E:\\test\\"
 3 drop_str= '_00001'
 4 #獲取該目錄下所有文件,存入列表中
 5 fileList=os.listdir(path)
 6 for file in fileList:
 7     old=path + file
 8     new=path + ''.join(file.split(drop_str))  #join和split方法
 9     os.rename(old, new)      #rename方法
10     print(old, '======>', new)

 


免責聲明!

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



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