字符批量替换程序asp服务器版(3)
set fso=server.createobject("scripting.filesystemobject")
dim filecode : set filecode=fso.opentextfile(path,1)
getfilecode=filecode.readall
set fso=nothing
else
getfilecode=path & "不存在该文件"
end if
end function
sub jstxt(txt) '使用JavaScript
response.write "<script type=""text/JavaScript"" language=""JavaScript"">"
response.write "<!--"&chr(13)&chr(10)
response.write txt
response.write chr(13)&chr(10)&"//-->"
response.write "</script>"
end sub
sub getfolderfile(cpath) '替换某一个(子)文件夹下的所有文件
response.flush
dim fso : set fso=server.createobject("scripting.filesystemobject")
if fso.folderexists(cpath)=false then
jstxt("alert("" "&replace(cpath,"\","\\") & "不存在该文件夹!"&" "") ")
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
内容版权声明:除非注明,否则皆为本站原创文章。