用脚本处理utf8的文本文件

时间:2022-07-04 21:07:41
filename="C:\Users\Administrator\Desktop\soft\x.txt"
filename2="C:\Users\Administrator\Desktop\soft\x.txt"

Dim txt 
Dim txt2
txt=ReadFromTextFile( filename )
txt=Replace( txt,"xx软件","yy软件" )


WriteToTextFile filename2,txt

Set a = CreateObject("Scripting.FileSystemObject")
a.CopyFile "C:\Users\Administrator\Desktop\soft\web.xml","C:\",true

msgbox "ok"


 Function ReadFromTextFile(FileUrl)
 dim str
 set stm=CreateObject("adodb.stream")
 stm.Type=2'以本模式读取
 stm.mode=3 
 stm.charset="UTF-8"
 stm.open
 stm.loadfromfile  FileUrl 
 str=stm.readtext
 stm.Close
 set stm=nothing
 ReadFromTextFile=str
End Function

Sub WriteToTextFile(FileUrl,byval Str)
 set stm=CreateObject("adodb.stream")
 stm.Type=2'以本模式读取
 stm.mode=3
 stm.charset="UTF-8"
 stm.open
 stm.WriteText str
 stm.SaveToFile  FileUrl ,2 
 stm.flush
 stm.Close
 set stm=nothing
End Sub