字符批量替换程序asp服务器版

2019-01-13 21:14:02刘景俊


#btm
{
    text-align:center;
    padding-top:8px;
    padding-bottom:8px;
    background:#ececec
}

textarea
{
    width:330;
    height:100px
}

#copyr
{
    font-size:9pt;
    text-align:center;
    color:silver
}
-->
</style>
</head>
<body>
<%
if request.querystring("add")="yes" then
%>
<div id="top">
    <div id="ftitle">程序处理结果</div>
    <div id="top_b">
        <div>
            总文件:<span style="color:red" id="allfile"> </span>个  
            替换过文件:<span style="color:red" id="repfile"> </span>个
        </div>
        <div><br />被替换过文件路径列表↓<textarea id="txtreple" style="overflow:auto"></textarea></div>
        <div id="copyr"><br />风云制作  hezhiwu5@163.com  2007-3-12</div>
    </div>
</div>
<%
dim oldstr :oldstr=request.form("lookstr")  '源字符串
dim newstr :newstr=request.form("replacestr") '新字符串
dim rep : rep=cbool(request.form("bak"))   '是否备份文件,true为备份文件
dim i : i=0  '总文件个数
dim j : j=0  '被替换的文件个数

function chkexistsfile(path) '判断一个文件是否存在,如果存在,返回true,否则返回false
    dim fso
    set fso=server.createobject("scripting.filesystemobject")
    if fso.fileexists(path) then
        chkexistsfile=true
    else
        chkexistsfile=false
    end if
    set fso=nothing
end function

function getfilecode(path) '获取一个文件的代码
    dim fso
    if chkexistsfile(path) then
        set fso=server.createobject("scripting.filesystemobject")
        dim filecode : set filecode=fso.opentextfile(path,1)
        getfilecode=filecode.readall
        set fso=nothing
    else
        getfilecode=path & "不存在该文件"
    end if
end function