Description
1, this tool can bulk replace the site asp,.txt,php,aspx ... And so on, text-type characters
2, will replace.asp upload to the site root directory, run http://site domain name/replace.asp
3. For safety, please delete or rename it after using this procedure
Copy Code code as follows:
<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<%option Explicit
Response.buffer=true
response.charset= "GB2312"
server.scripttimeout=9999999
%>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<meta http-equiv= "Content-language" content= "ZH-CN"/>
<title>iframe Replacement Program </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>
<body>
<%
If Request.QueryString ("add") = "yes" then
%>
<div id= "Top" >
<div id= "Ftitle" > Program processing Results </div>
<div id= "Top_b" >
<div>
Total file: <span style= "color:red" id= "Allfile" > </span>
Replace file: <span style= "color:red" id= "Repfile" > </span>
</div>
<div><br/> was replaced with a file path list ↓<textarea id= "Txtreple" style= "Height:300px;overflow:auto" ></textarea >
</div>
<div id= "Copyr" ><br/>
</div>
</div>
</div>
<%
Dim Oldstr:oldstr=request.form ("lookstr") ' Source string
Dim Newstr:newstr=request.form ("Replacestr") ' New string
Dim Rep:rep=cbool (Request.Form ("bak")) ' whether to back up files, true to backup files
Dim i:i=0 ' Total File count
Dim j:j=0 ' Number of files replaced
function Chkexistsfile (path) ' Determines whether a file exists, returns True if it exists, or returns 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 (templatefname) ' Gets the code for a file
Dim FSO, Fileobj, Filestreamobj
Set FSO = CreateObject ("Scripting.FileSystemObject")
If FSO. FileExists (templatefname) = False Then
Getfilecode= ""
Else
Set fileobj = FSO. GetFile (Templatefname)
Set filestreamobj = Fileobj.openastextstream (1)
If not Filestreamobj.atendofstream Then
Getfilecode = Filestreamobj.readall
End If
End If
Set FSO = Nothing:set Fileobj = Nothing:set Filestreamobj = Nothing
End Function
Sub Jstxt (TXT) ' uses JavaScript
Response.Write "<script type=" "Text/javascript" "language=" "JavaScript" ">"
Response.Write "<!--" (&CHR) &CHR (10)
Response.Write txt
Response.Write Chr (a) &CHR (a) & "//-->"
Response.Write "</script>"
End Sub
Sub Getfolderfile (ByVal cpath) ' Replaces all files under one (child) folder
Response.Flush
Dim Fso:set Fso=server.createobject ("Scripting.FileSystemObject")
If Fso.folderexists (CPath) =false Then
Jstxt ("Alert" "&replace (CPath," \ "," \ ") &" does not exist in this folder! " "&" ")")
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 (server. MapPath (Trim (Request.Form ("Pfolder"))) ' Calling program
Else
%>
<div id= "Top" >
<form action= "? Add=yes" method= "post" name= "Strform" >
<div id= "Ftitle" >iframe Bulk Replacement Program </div>
<div id= "Top_b" >
<div>
<p> folder address:
<input type= "text" size= "a" name= "Pfolder"/>
</p>
<p> such as root directory Please enter:/, specify the directory, please enter: "/directory/"
</p>
</div>
<div> Backup original file: <input type= "checkbox" Name= "bak" value= "true"/></div>
<div><br/> Find string ↓<textarea name= "Lookstr" rows= "ten" ></textarea>
</div>
<DIV><BR/> Replace the lookup string ↓<textarea name= "Replacestr" ></textarea></div>
<div id= "BTM" ><input type= "Submit" value= "OK"/></div>
<div id= "Copyr" ><br/>
</div>
</div>
</form>
</div>
<script type= "Text/javascript" language= "JavaScript" >
<!--
function Chk ()
{
var forma=document.strform;
if (forma.pfolder.value== "")
{
Alert ("folder address cannot be empty");
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 ("Find string cannot be empty!") ");
Forma.lookstr.focus ();
}
else if (forma.replacestr.value== "")
{
Alert ("Replace the found string cannot be empty");
Forma.replacestr.focus ();
}
Else
{
Forma.submit ();
}
}
-->
</SCRIPT>
<% End If%>
</body>