TESTEVERYTHING

Saturday, 25 June 2011

Creating Files Working with files(FileSystemObject) / QTP

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.
[VBScript]
Dim fso, f1
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile("c:\testfile.txt", True)
[JScript]
var fso, f1;
fso = new ActiveXObject("Scripting.FileSystemObject");
f1 = fso.CreateTextFile("c:\\testfile.txt", trThe second way to create a text file is to use the OpenTextFile method of the
FileSystemObject object with the ForWriting flag set.
[VBScript
Dim fso, ts
Const ForWriting = 2
Set fso = CreateObject("Scripting. FileSystemObject")
Set ts = fso.OpenTextFile("c:\test.txt", ForWriting, True)
[JScript]var fso, ts;var ForWriting= 2;fso = new ActiveXObject("Scripting.FileSystemObject")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.
[VBScript]
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

Which one is right ?

Translate







Tweet