文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>rename the file for specified folder and file type

rename the file for specified folder and file type

时间:2010-08-12  来源:angelia_liu

''' This script used to rename the file that you specified.
    Usage: rename.py parameter1 parameter2.
    parameter1 is the parent path(dir) of the file that you want to rename.
    parameter2 is the file type which you want to rename.
'''
import os
import re
import sys

def rename_p(path,file_type):
    path=path
    filenames=os.listdir(path)
    regx="^SPC.*"+"."+file_type+"$"
    #print regx
    
    for f in filenames:
        #print f
        if re.search(regx,f)!=None:
            '''Split the filename and extension'''
            oldname=os.path.splitext(f)[0]
            #print 'The old name is:', oldname
            ext=os.path.splitext(f)[1]
            #print 'The extentsion is:',ext
            #new_name='SPC_'+oldname+'.'+file_type
            new_name=oldname+'.'+'JPEG'
            os.rename(path+'\\'+f,path+'\\'+new_name)
    for f in os.listdir(path):
        print f
     
        
if __name__=='__main__':
    path=sys.argv[1]
    file_type=sys.argv[2]
    rename_p(path,file_type)


相关阅读 更多 +
排行榜 更多 +
mirrox模组(玩家自制)手机版下载

mirrox模组(玩家自制)手机版下载

休闲益智 下载
集装箱模拟器手机版下载安装

集装箱模拟器手机版下载安装

模拟经营 下载
哔咔漫画app下载免费2025

哔咔漫画app下载免费2025

浏览阅读 下载