- 论坛徽章:
- 1
|
# ------------复制下面的部分,保存为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)
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/100698/showart_2053626.html |
|