python之转换源码后缀名为txt后缀名
2015-11-18 22:37
471 查看
## 转换c/cpp文件为txt后缀名(手机browser阅读)的html列表
import os,sys,re import shutil,string def getList(dirname,pFunc): try: ls=os.listdir(dirname) except: print dirname,'is access deny' else: for file in ls: temp = os.path.join(dirname,file) if(os.path.isdir(temp)): getList(temp,pFunc) else: pFunc(dirname,file) #[OK] def getType(fname): pos = fname.rfind(".") if pos != -1: return fname[pos + 1:] return "" def printCppFile(dirname,file): if file == "dev.py" or file == "index.html": return m_type = getType(file) newFile = "%s.txt" % ( file.replace(".","_")) if m_type != "txt": oldName = os.path.join(dirname,file) newName = os.path.join(dirname,newFile) os.rename(oldName,newName) print "<a href=\"%s\">%s</a><hr>" % (file,file) def printHead(): print "<head>\n" print "<style>" print "a{ font-size:40; }" print "</style>" print "</head>" printHead() getList(os.getcwd(),printCppFile)
相关文章推荐
- python urllib模块
- leetcode Integer to Roman python
- python之模块hashlib(提供了常见的摘要算法,如MD5,SHA1等等)
- 练习PYTHON之EVENTLET
- python之WebSocket的开发
- 练习PYTHON之GEVENT
- Python pexpect出现错误‘module have no attribute "spawn" 解决办法
- Python/scikit-learn机器学习库(决策树)
- LeetCode OJ 系列之78 Subsets --Python
- python之string操作汇总
- python之实现ftp上传下载代码(含错误处理)
- python里面的函数参数
- 练习PYTHON协程之GREENLET
- python之模块ftplib(实现ftp上传下载代码)
- python_2
- [Python标准库]string——文本常量和模板
- python之模块ftplib(FTP协议的客户端)
- 树莓派2代B model 上手初体验,不用显示器,Python GPIO 点亮一颗LED
- Python基础学习-如何安装第三方库
- Numpy快速入门