**********字符批量替换程序asp服务器版******************
安装方法:直接把replace.asp文件放在任意的支持asp+FSO的环境中
运行方法:用http://localhost/.../replace.asp访问即可看到程序的效果
此程序的功能主要用来替换文件夹中所有文本文件字符用的。
如:txt、htm、asp、jsp、php、……一切的文本文件
div+CSS布局兼容FF和IE浏览器
---------目前具有功能------------------------
即时查看当前替换文件路径
可选备份原文件为“原文件.bak”
文件夹无限层嵌套替换字符
被替换文件路径显示
总文件数和被替换过文件数显示
...
程序用途举例-
清除类似的网页木马<iframesrc=""width="0"height="0"></iframe>
批量替换文件字符,少量的文件就用不上这个程序了
可上传在服务器上,在线替换批量替换字符
当“查找字符”和“替换的字符串”相同时,可以查找大量文本文件中,哪些文件包含有目标字符
....
155120699原创欢迎指正hezhiwu5@163.com21:472007-3-12
------------------------------------------------------------------------------------------------------
复制代码 代码如下:
<%OptionExplicit%>
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<metahttp-equiv="Content-Language"content="zh-CN"/>
<metaname="author"content="155120699编写hezhiwu5@163.com"/>
<metaname="Description"content="字符替换程序"/>
<metaname="copyright"content="155120699原创web程序欢迎指正"/>
<title>字符替换程序asp服务器版</title>
<styletype="text/css">
<>
</style>
</head>
<body>
<%
ifrequest.querystring("add")="yes"then
%>
<divid="top">
<divid="ftitle">程序处理结果</div>
<divid="top_b">
<div>
总文件:<spanstyle="color:red"id="allfile"></span>个
替换过文件:<spanstyle="color:red"id="repfile"></span>个
</div>
<div><br/>被替换过文件路径列表↓<textareaid="txtreple"style="overflow:auto"></textarea></div>
<divid="copyr"><br/>风云制作hezhiwu5@163.com2007-3-12</div>
</div>
</div>
<%
dimoldstr:oldstr=request.form("lookstr")'源字符串
dimnewstr:newstr=request.form("replacestr")'新字符串
dimrep:rep=cbool(request.form("bak"))'是否备份文件,true为备份文件
dimi:i=0'总文件个数
dimj:j=0'被替换的文件个数
functionchkexistsfile(path)'判断一个文件是否存在,如果存在,返回true,否则返回false
dimfso
setfso=server.createobject("scripting.filesystemobject")
iffso.fileexists(path)then
chkexistsfile=true
else
chkexistsfile=false
endif
setfso=nothing
endfunction
functiongetfilecode(path)'获取一个文件的代码
dimfso
ifchkexistsfile(path)then
setfso=server.createobject("scripting.filesystemobject")
dimfilecode:setfilecode=fso.opentextfile(path,1)
getfilecode=filecode.readall
setfso=nothing
else
getfilecode=path&"不存在该文件"
endif
endfunction
subjstxt(txt)'使用JavaScript
response.write"<scripttype=""text/JavaScript""language=""JavaScript"">"
response.write"<>"
response.write"</script>"
endsub
subgetfolderfile(cpath)'替换某一个(子)文件夹下的所有文件
response.flush
dimfso:setfso=server.createobject("scripting.filesystemobject")
iffso.folderexists(cpath)=falsethen
jstxt("alert("""&replace(cpath,"","")&"不存在该文件夹!"&""")")
response.end
endif
dimfolders:setfolders=fso.GetFolder(cpath)
dimsfile
foreachsfileinfolders.files
dimfilecode:filecode=getfilecode(sfile)
dimfilecode_b:filecode_b=filecode
ifinstr(filecode,oldstr)<>0andfso.GetExtensionName(sfile)<>"bak"then
jstxt("document.getElementById(""txtreple"").value+="""&replace(sfile,"","")&"rn"""&chr(13)&chr(10))
jstxt("window.status="""&replace(sfile,"","")&"""")
jstxt("document.title="""&replace(sfile,"","")&"""")
filecode=replace(filecode,oldstr,newstr)
dimnewfilecode:setnewfilecode=fso.opentextfile(sfile,2)
newfilecode.writefilecode
j=j+1
ifrepthen
dimnewfilecode_b:setnewfilecode_b=fso.opentextfile(sfile+".bak",2,true)
newfilecode_b.writefilecode_b
endif
endif
i=i+1
jstxt("document.getElementById(""allfile"").innerHTML="""&i&"""")
jstxt("document.getElementById(""repfile"").innerHTML="""&j&"""")
next
dimsfolder
foreachsfolderinfolders.subfolders
getfolderfile(sfolder)
next
setfso=nothing
endsub
getfolderfile(trim(request.form("pfolder")))'调用程序
else
%>
<divid="top">
<formaction="?add=yes"method="post"name="strform">
<divid="ftitle">字符批量替换程序</div>
<divid="top_b">
<div>文件夹地址:<inputtype="text"size="25"name="pfolder"/></div>
<div>备份原文件:<inputtype="checkbox"name="bak"value="true"/></div>
<div><br/>查找字符串↓<textareaname="lookstr"></textarea></div>
<div><br/>替换查找的字符串↓<textareaname="replacestr"></textarea></div>
<divid="btm"><inputtype="button"value="确定"onclick="chk()"/></div>
<divid="copyr"><br/>风云制作hezhiwu5@163.com2007-3-12</div>
</div>
</form>
</div>
<SCRIPTtype="text/javascript"LANGUAGE="JavaScript">
<>
</SCRIPT>
<%endif%>
</body>
</html>