国产探花免费观看_亚洲丰满少妇自慰呻吟_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
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 滕州市| 集贤县| 广南县| 武陟县| 张家界市| 潮安县| 商城县| 资溪县| 长寿区| 龙陵县| 班戈县| 三门峡市| 河津市| 博客| 遂平县| 嘉定区| 泊头市| 囊谦县| 饶河县| 东明县| 德令哈市| 巴林左旗| 岳阳县| 彝良县| 神农架林区| 荔浦县| 化德县| 桐梓县| 新津县| 招远市| 黄陵县| 大丰市| 白水县| 康平县| 南京市| 无为县| 桃江县| 成武县| 桐庐县| 蕉岭县| 葵青区|