字符批量替换程序asp服务器版

2019-01-13 21:14:02刘景俊

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,"","") & "rn""" &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&"""")