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

首頁 > 編程 > VBScript > 正文

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

2020-06-26 18:03:28
字體:
來源:轉載
供稿:網友
利用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
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 子洲县| 呼图壁县| 洪江市| 如东县| 密云县| 六安市| 彭水| 永城市| 南漳县| 林口县| 老河口市| 南华县| 湖州市| 基隆市| 小金县| 马山县| 皮山县| 义马市| 哈巴河县| 五寨县| 土默特左旗| 新昌县| 扎赉特旗| 上蔡县| 姜堰市| 宜春市| 西华县| 上林县| 泰和县| 安徽省| 定结县| 遂宁市| 洛阳市| 柏乡县| 巴塘县| 武汉市| 嵊泗县| 和龙市| 乳山市| 交口县| 陵川县|