|
ASP世界
ASP字符查找替换器
作者:Air 转自:Air的博客
最近我维护的一个网站(某净化工程网站)要修改几个词,但是这个词在网站上很多,而且整个网站的页面有数百个,如果一个一个修改或者本地修改后ftp上传的话,相当耗时间。我记的个webshell有个批量替换的功能,不过当我ftp上传这个文件的时候,却发现找不到这个文件,估计是被杀毒给灭了。
<%
'******************* 'asp版字符替换器 'By Air 'QQ:153580616 '******************* %> <form id="form1" name="form1" method="post" action=""> <label></label> <p> <label></label> </p> <br/> <table width="520" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#66CC99"> <tr bgcolor="#FFFFFF"> <td height="40" colspan="2" align="center" bgcolor="#57DB9C"><strong>ASP版字符替换器</strong></td> </tr> <tr bgcolor="#FFFFFF"> <td align="center">网站目录:</td> <td><label> <input name="WebMuLu" type="text" id="WebMuLu" size="40" value="<% if Request("WebMuLu")<>"" Then Response.Write(Request("WebMuLu")) else Response.Write(Server.MapPath("./")) End If%>" /> </label></td> </tr> <tr bgcolor="#FFFFFF"> <td width="127" align="center">文件后缀:</td> <td width="373"><input name="HouZhui" type="text" id="HouZhui" value="<%If Request("HouZhui")<>"" Then Response.Write(Request("HouZhui")) Else Response.Write("asp,html,htm") End If%>" size="40" /></td> </tr> <tr bgcolor="#FFFFFF"> <td align="center">替换模式:</td> <td><label> <input name="isReplace" type="checkbox" id="isReplace" <%If Request("isReplace") <>"" Then Response.Write("Checked")%> value="yes" /> </label></td> </tr> <tr bgcolor="#FFFFFF"> <td align="center">查找内容:</td> <td><textarea name="MuMaContent" cols="38" rows="4" id="MuMaContent"><%if Request("MuMaContent")<>"" Then Response.Write(Request("MuMaContent"))%></textarea></td> </tr> <tr bgcolor="#FFFFFF"> <td align="center">替换内容:</td> <td><textarea name="ReplaceStr" cols="38" rows="4" id="ReplaceStr"><%if Request("ReplaceStr")<>"" Then Response.Write(Request("ReplaceStr"))%></textarea></td> </tr> <tr bgcolor="#FFFFFF"> <td height="40" colspan="2" align="center"><input type="submit" name="Submit" value="搜索" /> <label> <input type="reset" name="Submit2" value="重置" /> </label></td> </tr> </table> <br /> </form> <% Function BianLi(path) Set fso=Server.CreateObject("Scripting.FileSystemObject") on error resume next set objFolder=fso.GetFolder(path) set objFiles=objFolder.Files for each objFile in objFiles for i = LBound(arr) to UBound(arr) if fso.GetExtensionName(objFile.Name) = arr(i) or arr(i) = "*.*" Then set f = fso.OpenTextFile(path + "" + objFile.Name,1) tmpstring = f.ReadAll if instr(tmpstring,Request("MuMaContent")) <> 0 Then response.Write(path + "" + objFile.Name +"<br>") j=j+1 if request("isReplace")="yes" and objFile.Name <> self then tmpstring = Replace(tmpstring,Request("MuMaContent"),Request("ReplaceStr")) set f = fso.OpenTextFile(path + ""+objFile.Name,2) f.write(tmpstring) f.close end if end if end if next next set objSubFolders=objFolder.Subfolders for each objSubFolder in objSubFolders nowpath=path + "" + objSubFolder.name bianli(nowpath) next set objFolder=nothing set objSubFolders=nothing set fso=nothing end function if request("Submit")<>"" Then dim arr,j,selfarr j=0 Server.ScriptTimeout=999999999 self = Request.ServerVariables("SCRIPT_NAME") selfarr = split(self,"/") self = selfarr(UBound(selfarr)) arr = split(request("HouZhui"),",") %> <table width="520" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#66CC99"> <tr bgcolor="#FFFFFF"> <td width="500" height="40" align="center" bgcolor="#57DB9C"><strong>查找结果</strong></td> </tr> <tr bgcolor="#FFFFFF"> <td height="40" align="left"> <% if Right(Request("WebMuLu"),1)="" Then WebMuLu = Left(Request("WebMuLu"),len(Request("WebMuLu"))-1) End If bianli(Request("WebMuLu")) Response.Write("<br/>") Response.Write("==================查找结果为 <font color=red>" &Cstr(j)&"</font> 个文件=================") %> </td> </tr> </table> <% End If %>
|