利用vbscript脚本修改文件内容,此适用于自动化的操作中
阿尔玛蓝,免费女装代理,射鸡英雄传
利用vbscript脚本修改文件内容,此适用于自动化的操作中
'新建一个replace.vbs脚本,脚本内容如下,程序运行时输入三个参数:查找内容,替换内容,文件
dim filename, find, replacewith, filecontents, dfilecontents
find = wscript.arguments(0)
replacewith = wscript.arguments(1)
filename = wscript.arguments(2)
'读取文件
filecontents = getfile(filename)
'用“替换内容”替换文件中所有“查找内容”
dfilecontents = replace(filecontents, find, replacewith, 1, -1, 1)
'比较源文件和替换后的文件
if dfilecontents <> filecontents then
'保存替换后的文件
writefile filename, dfilecontents
wscript.echo "replace done."
if len(replacewith) <> len(find) then
'计算替换总数
wscript.echo _
( (len(dfilecontents) - len(filecontents)) / (len(replacewith)-len(find)) ) & _
" replacements."
end if
else
wscript.echo "searched string not in the source file"
end if
'读取文件
function getfile(filename)
if filename<>"" then
dim fs, filestream
set fs = createobject("scripting.filesystemobject")
on error resume next
set filestream = fs.opentextfile(filename)
getfile = filestream.readall
end if
end function
'写文件
function writefile(filename, contents)
dim outstream, fs
on error resume next
set fs = createobject("scripting.filesystemobject")
set outstream = fs.opentextfile(filename, 2, true)
outstream.write contents
end function
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
-
-
-
-
用vbs实现文本循环读取
因为测试中需要读取一批url数据进行浏览,其实使用qtp本身的table能实现多种读取方式,但是因为需要tabel是使用excel保存的,在没有...
[阅读全文]
-
-
-
-
-
网友评论