将 当前目录 与子目录下的.sh文件全部重命名为.shell文件
- #!/usr/bin/python
- import os
- shpath='/usr/local/perl/test'
- filelist=os.listdir(shpath)
- f_object=os.walk(shpath)
- for i in f_object:
- #print i,'\n',i[2]
- #print '---------------'
- for j in i[2]:
- a=os.path.splitext(j)
- if a[1] == '.sh':
- print i[0]+'/'+j
- oldname=i[0]+'/'+j
- newname=i[0]+'/'+a[0]+'.shell'
- print oldname,'-->',newname
- os.rename(oldname,newname)
编辑回复