Creating Files
There are three ways to create an empty text file (sometimes referred to as a “text stream”).
The first way is to use the CreateTextFile method. The following example demonstrates how to create a text file using the CreateTextFileMethod method.
Dim fso, f1 Set fso = CreateObject("Scripting.FileSystemObject") Set f1 = fso.CreateTextFile("c:\testfile.txt", True) The second way to create a text file is to use the OpenTextFile method of the
FileSystemObject object with the ForWriting flag set.
Dim fso, ts Const ForWriting = 2 Set fso = CreateObject("Scripting. FileSystemObject") Set ts = fso.OpenTextFile("c:\test.txt", ForWriting, True)
A third way to create a text file is to use the OpenAsTextStream method with the ForWriting flag set.
Dim fso, f1, ts Const ForWriting = 2 Set fso = CreateObject("Scripting.FileSystemObject") fso.CreateTextFile ("c:\test1.txt") Set f1 = fso.GetFile("c:\test1.txt") Set ts = f1.OpenAsTextStream(ForWriting, True
No comments:
Post a Comment