您的位置:首页 > 编程语言 > Python开发

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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: