#-*-coding:utf-8-*-
import os
if __name__=='__main__':
old_ext=input('Please input the old ext:')
new_ext=input('Please input the new ext:')
for (path,dirs,filenames) in os.walk('/root/Programs'):
print 'jump in to the first for/n'
for filename in filenames:
ext=os.path.splitext(filename)[1]
print ext
if(cmp(old_ext,ext)==0):
new_name=filename.replace(ext,new_ext)
old_path=path+'/'+filename
new_path=path+'/'+new_name
print 'the old_path is'+old_path+'/n'
print 'the new_path is'+new_path+'/n'
os.rename(old_path,new_path)
python popen 是python os模块里的一个方法,它用来执行一些系统的命令
例如:
for i in os.popen('ls'):
print i