Chinaunix首页 | 论坛 | 博客
  • 博客访问: 236728
  • 博文数量: 27
  • 博客积分: 832
  • 博客等级: 准尉
  • 技术积分: 336
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-20 20:47
文章存档

2012年(9)

2010年(10)

2009年(7)

2008年(1)

我的朋友

分类: Python/Ruby

2009-09-16 22:58:58

  1. ======================转载文件=======================
  2. #coding:gbk 
  3. #code By Neeao 
  4. #2009-09-15 
  5. import os,string 
  6. def s_rename(path,old_ext,new_ext): 
  7.     for (path, dirs, files) in os.walk(path): 
  8.         for filename in files: 
  9.             ext=os.path.splitext(filename)[1
  10.             if (cmp(ext,old_ext)==0): 
  11.                 newname=filename.replace(old_ext,new_ext) 
  12.                 oldpath=path+"\\"+filename 
  13.                 newpath=path+"\\"+newname 
  14.                 print "oldpath:"+oldpath+"" 
  15.                 print "newpth:"+newpath+"" 
  16.                 try
  17.                     os.rename(oldpath, newpath) 
  18.                 except ValueError: 
  19.                     print "Error when rename the file " + oldpath 
  20.                 except NameError: 
  21.                     print "Error when rename the file " + oldpath 
  22.                 except OSError: 
  23.                     #print OSError 
  24.                     print newpath + " The file is already exist!" 
  25. if __name__ == '__main__'
  26.     s_rename("F:\\code",".ph",".pl"
  27.     #print "test" 
阅读(1150) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~