利用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
'新建一个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
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“利用vbscript脚本修改文件内容,此适用于自动化的操作中”评论...
更新动态
2024年05月10日
2024年05月10日
- 中唱《好歌珍藏--民族风情》2CD[WAV]
- 【古典音乐】拉罗查《舒曼钢琴作品》1971[FLAC+CUE整轨]
- 杨幂新片火锅撤档引吐槽 网友:哪个档都不好看
- 伊芙美如画!《剑星》官方分享伊芙早期概念设计图
- 《黑袍纠察队》第四季最新预告:V世代加盟 阿祖更癫了!
- 群星《民歌试音》[WAV分轨][630M]
- 刘若英《老歌回忆录》原抓 [WAV+CUE][569M]
- 汽车音响协会指定专用试音碟《名车顶级DJ试音王》DSD 2CD[APE+CUE][493M]
- 彭健新.1979-一阙短歌(2008年环球复黑王)【宝丽金】【WAV+CUE】
- 法老.2022-退潮【派嗨拜浪】【FLAC分轨】
- 群星.2010-不了情101.4CD【丽风】【WAV+CUE】
- 欢乐钓鱼大师钰上青花怎么钓 欢乐钓鱼大师钰上青花钓鱼方法
- 欢乐钓鱼大师怎么注销账号 欢乐钓鱼大师注销账号方法介绍
- 欢乐钓鱼大师新手怎么玩 欢乐钓鱼大师新手游玩攻略
- 【古典音乐】《美妙的管弦乐作品(第一辑)》2CD.1999[FLAC+CUE]