欢迎来到代码驿站!

ASP代码

当前位置:首页 > 软件编程 > ASP代码

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

时间:2022-12-23 11:50:17|栏目:ASP代码|点击:
**********字符批量替换程序asp服务器版******************
安装方法:直接把replace.asp文件放在任意的支持asp+FSO的环境中
运行方法:用http://localhost/.../replace.asp访问即可看到程序的效果
此程序的功能主要用来替换文件夹中所有文本文件字符用的。
如:txt、htm、asp、jsp、php、…… 一切的文本文件
div+CSS布局  兼容FF和IE浏览器
---------目前具有功能------------------------
即时查看当前替换文件路径
可选备份原文件为 “原文件.bak”
文件夹无限层嵌套替换字符
被替换文件路径显示
总文件数和被替换过文件数显示
...
程序用途举例-
清除类似的网页木马<iframe src="" width="0" height="0"></iframe>
批量替换文件字符,少量的文件就用不上这个程序了
可上传在服务器上,在线替换批量替换字符
当“查找字符”和“替换的字符串”相同时,可以查找大量文本文件中,哪些文件包含有目标字符
....
155120699原创  欢迎指正    hezhiwu5@163.com    21:47 2007-3-12  
------------------------------------------------------------------------------------------------------
复制代码 代码如下:

<%Option Explicit%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Content-Language" content="zh-CN" />
<meta name="author" content="155120699编写  hezhiwu5@163.com " />
<meta name="Description" content="字符替换程序" />
<meta name="copyright" content="155120699原创web程序 欢迎指正"/>
<title>字符替换程序asp服务器版</title>
<style type="text/css">
<!--
#top
{
    text-align:center;
    margin:auto;
    font-size:11pt;
}

#top_b
{
    text-align:left;
    width:350px;
    border:1px solid #000000;
    margin:auto;
    padding:0px;
    line-height:200%;
}

#top_b div
{
    padding-left:8px;
    padding-right:8px;
}

#ftitle
{
    text-align:center;
    width:350px;
    background:silver;
    font-weight:bold;
    letter-spacing:5px;
    font-size:15pt;
    padding:3px 0 3px 0;
    color:red;
    margin:auto;
    border:1px solid #000000;
    border-width:1px 1px 0 1px;
}

#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">&nbsp;</span>个&nbsp;&nbsp;
            替换过文件:<span style="color:red" id="repfile">&nbsp;</span>个
        </div>
        <div><br />被替换过文件路径列表↓<textarea id="txtreple" style="overflow:auto"></textarea></div>
        <div id="copyr"><br />风云制作&nbsp;&nbsp;hezhiwu5@163.com&nbsp;&nbsp;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

sub jstxt(txt) '使用JavaScript
    response.write "<script type=""text/JavaScript"" language=""JavaScript"">"
    response.write "<!--"&chr(13)&chr(10)
    response.write txt
    response.write chr(13)&chr(10)&"//-->"
    response.write "</script>"
end sub


sub getfolderfile(cpath) '替换某一个(子)文件夹下的所有文件

    response.flush
    dim fso : set fso=server.createobject("scripting.filesystemobject")
    if fso.folderexists(cpath)=false then 
        jstxt("alert("" "&replace(cpath,"\","\\") & "不存在该文件夹!"&" "") ")
        response.end
    end if
    dim folders : set folders=fso.GetFolder(cpath)
    dim sfile
    for each sfile in folders.files
        dim filecode : filecode=getfilecode(sfile)
        dim filecode_b : filecode_b=filecode
        if instr(filecode,oldstr) <> 0 and fso.GetExtensionName(sfile) <> "bak" then

            jstxt("document.getElementById(""txtreple"").value+="""& replace(sfile,"\","\\") & "\r\n""" &chr(13)&chr(10))
            jstxt("window.status="""& replace(sfile,"\","\\")&"""")
            jstxt("document.title="""& replace(sfile,"\","\\")&"""")

            filecode=replace(filecode,oldstr,newstr)
            dim newfilecode : set newfilecode=fso.opentextfile(sfile,2)
            newfilecode.write filecode
            j=j+1
            if rep then
                dim newfilecode_b : set newfilecode_b=fso.opentextfile(sfile+".bak",2,true)
                newfilecode_b.write filecode_b
            end if
        end if
        i=i+1
        jstxt("document.getElementById(""allfile"").innerHTML="""&i&"""")
        jstxt("document.getElementById(""repfile"").innerHTML="""&j&"""")

    next

    dim sfolder
    for each sfolder in folders.subfolders
        getfolderfile(sfolder)
    next
    set fso=nothing


end sub


getfolderfile(trim(request.form("pfolder"))) '调用程序

else
%>
<div id="top">

    <form action="?add=yes" method="post" name="strform">

        <div id="ftitle">字符批量替换程序</div>
        <div id="top_b">

            <div>文件夹地址:<input type="text" size="25" name="pfolder"/></div>
            <div>备份原文件:<input type="checkbox" name="bak" value="true" /></div>
            <div><br />查找字符串↓<textarea name="lookstr"></textarea></div>
            <div><br />替换查找的字符串↓<textarea name="replacestr"></textarea></div>
            <div id="btm"><input type="button" value="&nbsp;确定&nbsp;" onclick="chk()"/></div>
            <div id="copyr"><br />风云制作&nbsp;&nbsp;hezhiwu5@163.com&nbsp;&nbsp;2007-3-12</div>

        </div>

    </form>
</div>
<SCRIPT type="text/javascript" LANGUAGE="JavaScript">
<!--
function chk()
{
    var forma=document.strform;
    if(forma.pfolder.value=="")
    {
        alert("文件夹地址不能为空");
        forma.pfolder.focus();
        return;
    }
    else 
    {
        forma.pfolder.value=forma.pfolder.value.replace(/\//g,"\\");
        forma.pfolder.value=forma.pfolder.value.replace(/。/g,".");
    }
    if(forma.lookstr.value=="")
    {
        alert("查找字符串不能为空!");
        forma.lookstr.focus();
    }
    else if(forma.replacestr.value=="")
    {
        alert("替换查找的字符串不能为空");
        forma.replacestr.focus();
    }
    else
    {
        forma.submit();
    }
}
//-->
</SCRIPT>
<% end if %>
</body>
</html>

上一篇:CacheCls缓存的应用

栏    目:ASP代码

下一篇:没有了

本文标题:字符批量替换程序asp服务器版

本文地址:http://www.codeinn.net/misctech/222040.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有