|
文件: | 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)
阅读(775) | 评论(0) | 转发(0) |