服务器上批量替换html内的字符,字符批量替换程序asp服务器版

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

安装方法:直接把replace.asp文件放在任意的支持asp+FSO的环境中

运行方法:用http://localhost/.../replace.asp访问即可看到程序的效果

此程序的功能主要用来替换文件夹中所有文本文件字符用的。

如:txt、htm、asp、jsp、php、…… 一切的文本文件

div+CSS布局  兼容FF和IE浏览器

---------目前具有功能------------------------

即时查看当前替换文件路径

可选备份原文件为 “原文件.bak”

文件夹无限层嵌套替换字符

被替换文件路径显示

总文件数和被替换过文件数显示

...

程序用途举例-

清除类似的网页木马

批量替换文件字符,少量的文件就用不上这个程序了

可上传在服务器上,在线替换批量替换字符

当“查找字符”和“替换的字符串”相同时,可以查找大量文本文件中,哪些文件包含有目标字符

....

155120699原创  欢迎指正    hezhiwu5@163.com    21:47 2007-3-12

------------------------------------------------------------------------------------------------------

字符替换程序asp服务器版

if request.querystring("add")="yes" then

%>

程序处理结果

总文件: 个  

替换过文件: 个


被替换过文件路径列表↓

风云制作  hezhiwu5@163.com  2007-3-12

dim oldstr :oldstr=request.form("lookstr")  '源字符串

dim newstr :newstr=request.form("replacestr") '新字符串

dim rep : rep=cbool(request.form("bak"))   '是否备份文件,true为备份文件

dim i : i=0  '总文件个数

dim j : j=0  '被替换的文件个数

function chkexistsfile(path) '判断一个文件是否存在,如果存在,返回true,否则返回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(path) '获取一个文件的代码

dim fso

if chkexistsfile(path) then

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 "

response.write ""

response.write ""

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

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(trim(request.form("pfolder"))) '调用程序

else

%>

字符批量替换程序
文件夹地址:
备份原文件:

查找字符串↓

替换查找的字符串↓

风云制作  hezhiwu5@163.com  2007-3-12
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在VBA中批量替换工作薄字符串可以通过以下步骤实现: 1. 打开目标工作薄,可以使用Open方法打开或者直接使用Workbooks集合中的目标工作薄。 2. 遍历目标工作薄的所有工作表,可以使用For Each循环遍历Worksheets集合。 3. 在每个工作表中,使用Range对象的Replace方法来替换指定的字符串。 4. 确定要替换字符串以及替换后的字符串。可以使用InputBox获取用户输入的字符串,或者在VBA代码中提前指定。 以下是一个示例代码: ```vba Sub 批量替换工作薄字符串() Dim wb As Workbook Dim ws As Worksheet Dim findStr As String Dim replaceStr As String ' 打开目标工作薄 Set wb = Workbooks.Open("目标工作薄路径") ' 获取要替换字符串 findStr = InputBox("请输入要替换字符串:") ' 获取替换后的字符串 replaceStr = InputBox("请输入替换后的字符串:") ' 遍历所有工作表 For Each ws In wb.Worksheets ' 替换工作表中的字符串 ws.Cells.Replace What:=findStr, Replacement:=replaceStr, LookAt:=xlPart, _ MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False Next ws ' 关闭保存工作薄 wb.Close SaveChanges:=True End Sub ``` 运行上述代码后,程序会先弹出两个输入框分别让您输入要替换字符串和替换后的字符串,然后会逐个替换目标工作薄中的每个工作表中的字符串。最后,工作薄会自动关闭并保存修改。请确保目标工作薄的文件路径和名称正确填写。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值