python之转换源码后缀名为txt后缀名

本文介绍如何使用Python将C/C++源代码文件的后缀名批量转换为TXT,以便于在手机浏览器中方便阅读HTML列表格式。
摘要由CSDN通过智能技术生成

## 转换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,ne
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值