<%
response.charset="gb2312"
response.buffer=true
pathStr="/" '路径
code="id=""scr7ipt" '特征码
content="" '要替换的内容
set fso=server.createobject("scripting.filesystemobject")
temp_path=server.mappath(pathStr) '要遍历的文件夹路径
p_path=server.mappath(pathStr)
call getcount(temp_path)
Function getcount(path)
t_path=path
set fod=fso.getfolder(t_path)
o_c=o_c+fod.subfolders.count
f_c=f_c+fod.files.count
'遍历文件夹中的文件
if fod.files.count>0 then
for each fi in fod.files
response.write replace(t_path,p_path,"")&"\"&fi.name&"<br />"&vbcrlf
FileRewrite t_path&"\"&fi.name,code,content
next
end if
'遍历文件夹中的子文件夹,并回归调用
if fod.subfolders.count>0 then
for each ff in fod.subfolders
response.write "<font color=green>"&replace(t_path,p_path,"")&"\"&ff.name&" 目录</font><br />"&vbcrlf
response.flush '输出
c_fod=t_path&"\"&ff.name
call getcount(c_fod)
next
end if
end function
%>
<%
function FileRewrite(fileName,feaCode,content)
set f1=fso.OpenTextFile(fileName,1,false)
If Not f1.AtEndofStream Then
tempcnt=f1.readall
f1.close
if instr(tempcnt,feaCode)>0 then
temparray = Split(tempcnt,Chr(13)&Chr(10))
for i=0 to ubound(temparray)
tmpstr=""
tmpstr=temparray(i)
if instr(tmpstr,feaCode)>0 then
temparray(i)=content
end if
next
tempcnt = join(temparray,Chr(13)&Chr(10))
tempcnt=replace(tempcnt,Chr(13)&Chr(10)&Chr(13)&Chr(10),Chr(13)&Chr(10))
on error resume next
set f2=fso.OpenTextFile(fileName,2,false)
f2.write(tempcnt)
if err.number>0 then
response.write replace(filename,p_path,"")&" <font color=red>该文件存在代码但没有权限</font><br />"&vbcrlf
else
response.Write(replace(filename,p_path,"")&"<font color=red>替换完毕</font><br>"&vbcrlf)
end if
err.clear
f2.close
end if
End If
End Function
%>
<%
Function URLDecode(enStr)
dim deStr
dim c,i,v
deStr=""
for i=1 to len(enStr)
c=Mid(enStr,i,1)
if c="%" then
v=eval("&h"+Mid(enStr,i+1,2))
if v<128 then
deStr=deStr&chr(v)
i=i+2
else
if isvalidhex(mid(enstr,i,3)) then
if isvalidhex(mid(enstr,i+3,3)) then
v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))
deStr=deStr&chr(v)
i=i+5
else
v=eval("&h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1)))))
deStr=deStr&chr(v)
i=i+3
end if
else
destr=destr&c
end if
end if
else
if c="+" then
deStr=deStr&" "
else
deStr=deStr&c
end if
end if
next
URLDecode=deStr
end function
function isvalidhex(str)
isvalidhex=true
str=ucase(str)
if len(str)<>3 then isvalidhex=false:exit function
if left(str,1)<>"%" then isvalidhex=false:exit function
c=mid(str,2,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
c=mid(str,3,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
end function
%>