python批量重命名【截取文件名前六個字符 】


 

 

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os, sys

# 打開文件
path = "/home/landv/Desktop/l/"
dirs = os.listdir( path )

# 輸出所有文件和文件夾
for file in dirs:
    if os.path.splitext(file)[1] == '.jpg':  
        new=file[0:6]#截取文件名前六個字符        
        os.rename(file,new)#進行重命名
        #print file

 


免責聲明!

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



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