另一种打开文件对象的方法
,y!`I'a4O*[0Function TextStreamTest51Testing软件测试网2S~)Ss dSy
Const ForReading = 1, ForWriting = 2, ForAppending = 8
g.y'Ie]K0 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
`7Rp8M[f/H0 Dim fso, f, ts
*J%|&p$Q$Gc!{-B^Q0t\0 Set fso = CreateObject("Scripting.FileSystemObject")51Testing软件测试网2~? X%D kg8l"xv-ci
Set f = fso.GetFile("c:\test1.txt")51Testing软件测试网0?!rw@H
Set ts =f.OpenAsTextStream(ForWriting,TristateUseDefault)51Testing软件测试网Knbg1Fi
ts.Write "Hello World"
ly%oV%}2o/V
I"pI0‘可写world,但读取时出现乱码51Testing软件测试网Q#Mg8vLg3P
ts.Close
Dtu!`uq7`2L g0 Set ts =f.OpenAsTextStream(ForReading,TristateUseDefault)
aW&p-`5i1F0 TextStreamTest = ts.ReadLine
.k+C,M3k [w
lz}
_m0 ts.Close51Testing软件测试网Ax/b'}KP+E~
End Function51Testing软件测试网U,Y%xMA.m@ N{+@sa.BD
UDwti9Vc0 '创建文件
*J/nc:n/_P8Cp#Z%D0Sub CreateAfile
r aw A gB0 Dim fso, MyFile
:Mqd+J ^!d V0 Set fso = CreateObject("Scripting.FileSystemObject")51Testing软件测试网yDr:o^/J
Set MyFile = fso.CreateTextFile("c:\testfile.txt",True)51Testing软件测试网k @XZ H"HO
MyFile.WriteLine("This is a test.")51Testing软件测试网tRD Sv:F
MyFile.Close
.]*P+aD:o0End Sub
iy4|a)J\#h"G3x0 51Testing软件测试网8G.bmPJ+c
'copy、move、delete操作
Nn(g*Gc3YS n0Dim fso, MyFile
7DPGVfbH J
}0Set fso = CreateObject("Scripting.FileSystemObject")51Testing软件测试网
?Z%r7i+F6iWr(l
Set MyFile = fso.GetFile("c:\testfile.txt")
g S4gOM3s*a0MyFile.Copy ("c:\windows\desktop\test2.txt")51Testing软件测试网,Dg.W!f7V-Y
MyFile.move ("c:\windows\desktop\test2.txt")
E@2P|X;ZM0MyFile.delete
.?l%e+ZSoe0 51Testing软件测试网N2vci6lw]Eg