O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Folder.CreateTextFile Method

Syntax

                  oFolderObj
                  .CreateTextFile FileName[, Overwrite[, Unicode]])
oFolderObj

Use: Required

Data Type: Folder object

A Folder object.

FileName

Use: Required

Data Type: String

Any valid filename and optional path.

Overwrite

Use: Optional

Data Type: Boolean

Flag to indicate whether an existing file of the same name should be overwritten.

Unicode

Use: Optional

Data Type: Boolean

Flag to indicate whether file is to be written in Unicode or ASCII.

Return Value

A TextStream object.

Description

Creates a new file at the specified location and returns a TextStream object for that file.

Rules at a Glance

  • Filename can be a relative or absolute path. Wildcard characters are not allowed in FileName.

  • If no path is specified in Filename, the script’s current drive and directory are used. If no drive is specified in Filename, the script’s current drive is used.

  • The default value for Overwrite is False.

  • If Unicode is set to True, a Unicode file is created; otherwise it’s created as an ASCII text file.

  • The default value for Unicode is False.

Programming Tips and Gotchas

  • If the path specified in Filename does not exist, the method fails. To prevent this error, you can use the FileSystemObject object’s FolderExists method to be sure that the path is valid.

  • 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 file referred to in Filename already exists as a read-only file, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required