使用VBScript读取txt文件并写入

上一篇 / 下一篇  2011-06-24 17:50:19

'这个是读取文件(文件先存在,否则报错)

Option Explicit
Const ForReading=1,ForWriting=2,ForAppending=8
dim fso,file,msg
Set fso=CreateObject("Scripting.FileSystemObject")
Set file=fso.OpenTextFile("c:\calc.txt",ForReading)
while(Not file.AtEndOfLine)
 msg=msg&file.ReadLine&vbCrLf  ' 回车符与换行符:vbCrLf=Chr(13)&Chr(10)
Wend
MsgBox msg
file.Close
Set file=Nothing
Set fso=Nothing

'向E盘 result.txt文件中写入(固定)数据

set fso=CreateObject("Scripting.FileSystemObject")
set fw=fso.createtextfile("e:\result.txt",2) '创建txt文件
fw.writeline("vbs123")
fw.writeline("你好,可以吗?")
set ws=CreateObject("wscript.shell")
ws.run "c:\windows\system32\notepad.Exe e:\result.txt"


TAG:

 

评分:0

我来说两句

日历

« 2024-05-15  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 1385
  • 日志数: 3
  • 建立时间: 2011-05-07
  • 更新时间: 2011-06-24

RSS订阅

Open Toolbar