文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>重命名文件

重命名文件

时间:2010-05-24  来源:angelia_liu

import os
import re

def rename_p(path,file_type):
    path=path
    filenames=os.listdir(path)
    regx="."+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]  #Get the file extension
            # print 'The extentsion is:',ext
            new_name=oldname+'new'+'.'+file_type
            os.rename(path+'\\'+f,path+'\\'+new_name)
    for f in os.listdir(path):
        print f
        
        

if __name__=='__main__':
    #print 'Please input the dir/path which you want to rename the files in'
    path=raw_input('Please input the dir/path which you want to rename the files in:')
    file_type=raw_input('\nPlease input the file type that you want to rename:')
    if not os.path.isdir(path):
        print path+' is not exist.'
    else:
        rename_p(path,file_type)


相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载