Chinaunix首页 | 论坛 | 博客
  • 博客访问: 762757
  • 博文数量: 230
  • 博客积分: 6330
  • 博客等级: 准将
  • 技术积分: 2188
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-10 15:55
个人简介

脚踏实地

文章分类

全部博文(230)

文章存档

2017年(1)

2016年(7)

2015年(10)

2014年(32)

2013年(24)

2012年(33)

2011年(50)

2010年(30)

2009年(43)

分类: LINUX

2009-09-16 13:27:36

文件:rename.py.zip
大小:0KB
下载:下载

法1 下载上面的文件,进入apue2e目录后解压执行

法2 
----进入apue2e目录后-复制下面的部分,保存为rename.py,然后python  rename.py即可
文件为:---------
#!/usr/bin/python
''' Miao--add '.c' to each file name in this file folder
         e.g.  fig7.24 is divided into 'fig7'  and '.24'
     Note: ****
        If the file name is just a word, len(os.path.splitext(base)) is also 2.  
            "os.path.splitext(base)[1]" is ''!'''
import os

files = os.listdir(os.getcwd())

for file in files:
    base = os.path.basename(file)
    count= len(os.path.splitext(base))
    if count==2:
        ext = os.path.splitext(base)[1]
        name = os.path.splitext(base)[0]
        flag=False
        cnt=len(ext)
        for ii in range(0,cnt):
            if ext[ii]=='.' or '0'<=ext[ii]<='9':
                flag=True
                pass
            else:
                flag=False
                break
        if flag==True:
            newname=name+ext+'.c'
            os.rename(file,newname)

 
阅读(736) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~