Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Scripting
Script Runtime
FileSystemObject
 CreateTextFile Method
This page is specific to
.NET Framework 3.0

Other versions are also available for the following:
Scripting Runtime Library
CreateTextFile Method

Updated: November 2007

Creates a specified file name and returns a TextStream object that can be used to read from or write to the file.

object.CreateTextFile(filename[, overwrite[, unicode]])
object

Required. Always the name of a FileSystemObject or Folder object.

filename

Required. String expression that identifies the file to create.

overwrite

Optional. Boolean value that indicates whether you can overwrite an existing file. The value is true if the file can be overwritten, false if it can't be overwritten. If omitted, existing files are not overwritten.

unicode

Optional. Boolean value that indicates whether the file is created as a Unicode or ASCII file. The value is true if the file is created as a Unicode file, false if it's created as an ASCII file. If omitted, an ASCII file is assumed.

The following code illustrates how to use the CreateTextFile method to create and open a text file.

JScript
var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.CreateTextFile("c:\\testfile.txt", true);
a.WriteLine("This is a test.");
a.Close();

Sub CreateAfile
   Dim fso, MyFile
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set MyFile = fso.CreateTextFile("c:\testfile.txt", True)
   MyFile.WriteLine("This is a test.")
   MyFile.Close
End Sub

If the overwrite argument is false, or is not provided, for a filename that already exists, an error occurs.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker