用asp实现的iframe批量替换工具

2018-09-06 11:45

阅读:332

  说明:
1、此工具可以批量替换网站上asp,.txt,php,aspx...等等文本型的字符
2、将replace.asp上传至网站根目录后,运行站域名/replace.asp
3、为了安全,使用本程序后请删除或更名
复制代码 代码如下:
<%@LANGUAGE=VBSCRIPTCODEPAGE=936%>
<%optionexplicit
Response.Buffer=true
Response.CharSet=GB2312
Server.ScriptTimeout=9999999
%>
<html>
<head>
<metahttp-equiv=Content-Typecontent=text/html;charset=gb2312/>
<metahttp-equiv=Content-Languagecontent=zh-CN/>
<title>Iframe替换程序</title>
<styletype=text/css>
<!--
#top
{
text-align:center;
margin:auto;
font-size:11pt;
}
#top_b
{
text-align:left;
width:350px;
border:1pxsolid#000000;
margin:auto;
padding:0px;
line-height:200%;
}
#top_bdiv
{
padding-left:8px;
padding-right:8px;
}
#ftitle
{
text-align:center;
width:350px;
background:silver;
font-weight:bold;
letter-spacing:5px;
font-size:15pt;
padding:3px03px0;
color:red;
margin:auto;
border:1pxsolid#000000;
border-width:1px1px01px;
}
#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>
<%
ifrequest.querystring(add)=yesthen
%>
<divid=top>
<divid=ftitle>程序处理结果</div>
<divid=top_b>
<div>
总文件:<spanstyle=color:redid=allfile></span>个
替换过文件:<spanstyle=color:redid=repfile></span>个
</div>
<div><br/>被替换过文件路径列表↓<textareaid=txtreplestyle=height:300px;overflow:auto></textarea>
</div>
<divid=copyr><br/>
</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(TemplateFname)获取一个文件的代码
DimFSO,FileObj,FileStreamObj
SetFSO=CreateObject(scripting.filesystemobject)
IfFSO.FileExists(TemplateFname)=FalseThen
getfilecode=
Else
SetFileObj=FSO.GetFile(TemplateFname)
SetFileStreamObj=FileObj.OpenAsTextStream(1)
IfNotFileStreamObj.AtEndOfStreamThen
getfilecode=FileStreamObj.ReadAll
EndIf
EndIf
SetFSO=Nothing:SetFileObj=Nothing:SetFileStreamObj=Nothing
endfunction
subjstxt(txt)使用JavaScript
response.write<scripttype=text/JavaScriptlanguage=JavaScript>
response.write<!--&chr(13)&chr(10)
response.writetxt
response.writechr(13)&chr(10)&//-->
response.write</script>
endsub

subgetfolderfile(byvalcpath)替换某一个(子)文件夹下的所有文件
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)<>bakthen
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)
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(repfile).innerHTML=&j&)
next
dimsfolder
foreachsfolderinfolders.subfolders
getfolderfile(sfolder)
next
setfso=nothing

endsub

getfolderfile(server.MapPath(trim(request.form(pfolder))))调用程序
else
%>
<divid=top>
<formaction=?add=yesmethod=postname=strform>
<divid=ftitle>Iframe批量替换程序</div>
<divid=top_b>
<div>
<p>文件夹地址:
<inputtype=textsize=25name=pfolder/>
</p>
<p>如根目录请输入:/,指定目录,请输入:"/目录/"
</p>
</div>
<div>备份原文件:<inputtype=checkboxname=bakvalue=true/></div>
<div><br/>查找字符串↓<textareaname=lookstrrows=10></textarea>
</div>
<div><br/>替换查找的字符串↓<textareaname=replacestr></textarea></div>
<divid=btm><inputtype=submitvalue=确定/></div>
<divid=copyr><br/>
</div>
</div>
</form>
</div>
<SCRIPTtype=text/javascriptLANGUAGE=JavaScript>
<!--
functionchk()
{
varforma=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();
}
elseif(forma.replacestr.value==)
{
alert(替换查找的字符串不能为空);
forma.replacestr.focus();
}
else
{
forma.submit();
}
}
//-->
</SCRIPT>
<%endif%>
</body>
</html>


评论


亲,登录后才可以留言!