Name
FileSystemObject.CreateTextFile Method
Syntax
oFileSysObj
.CreateTextFileFilename
[,Overwrite
[,Unicode
]])
-
oFileSysObj
Use: Required
Data Subtype: FileSystemObject object
Any object variable returning a FileSystemObject object.
-
Filename
Use: Required
Data Subtype: String
Any valid filename, along with an optional path.
-
Overwrite
Use: Optional
Data Subtype: Boolean
Flag indicating if an existing file of the same name should be overwritten.
-
Unicode
Use: Optional
Variant Sub Type: Boolean
Flag indicating if
Filename
is to be written in Unicode or ASCII.
Return Value
A TextStream object.
Description
Creates a new file and returns its TextStream object.
Rules at a Glance
Wildcard characters aren’t allowed in
Filename
.Filename
can be a relative or absolute path.If no path is specified in
Filename
, the script’s current drive and directory are used. If no drive is specified inFilename
, the script’s current drive is used.If the path specified in
Filename
doesn’t exist, the method fails. To prevent this error, you can use the FileSystemObject object’s FolderExists method to insure that the path is valid.The default value for
Overwrite
isFalse
.If
Unicode
is set toTrue
, the file is created in Unicode; otherwise, it’s created as an ASCII text file. The default value forUnicode
isFalse
.
Programming Tips & Gotchas
The newly created text file is automatically opened only for writing. If you subsequently wish to read from the file, you must first close it and reopen it in read mode.
If the path referred ...
Get VBScript in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.