国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > VBScript > 正文

利用vbscript腳本修改文件內容,此適用于自動化的操作中

2020-07-26 12:06:36
字體:
來源:轉載
供稿:網友
利用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
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 罗甸县| 千阳县| 广平县| 临城县| 合江县| 监利县| 清涧县| 北流市| 会宁县| 宜城市| 巴中市| 西峡县| 靖宇县| 南皮县| 金堂县| 沂源县| 石城县| 隆德县| 屏南县| 吉隆县| 土默特右旗| 汝州市| 江安县| 拜城县| 罗城| 门源| 阿尔山市| 冀州市| 邢台县| 礼泉县| 高密市| 法库县| 涿州市| 自贡市| 嘉善县| 宜宾县| 新宾| 宁安市| 东山县| 东乌珠穆沁旗| 盐边县|