O'Reilly logo

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

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

FileSystemObject.OpenTextFile Method

Syntax

                  oFileSysObj
                  .OpenTextFile(FileName[, IOMode[, Create[, Format]]])
oFileSysObj

Use: Required

Data Subtype: FileSystemObject object

Any object variable returning a FileSystemObject object.

FileName

Use: Required

Data Subtype: String

The path and filename of the file to open.

IOMode

Use: Optional

Data Subtype: Long

A constant specifying the purpose for opening the file.

Create

Use: Optional

Data Subtype: Boolean

A Boolean flag denoting whether the file should be created if it can’t be found in the given path.

Format

Use: Optional

Data Subtype: Long

A constant specifying ASCII or Unicode format.

Return Value

A TextStream object.

Description

Opens (and optionally first creates) a text file for reading or writing.

Rules at a Glance

  • File open (IOMode) values are:

    Constant

    Value

    Description

    ForAppending

    8

    Opens the file for appending; that is, the current contents of the file are protected and new data written to the file is placed at the end of the file.

    ForReading

    1

    Opens the file for reading; ForReading files are read-only.

    ForWriting

    2

    Opens the file for writing; all previous file content is overwritten by new data.

  • Tristate (Format) values are:

    Constant

    Value

    Description

    TristateUseDefault

    -2

    Opens as System default

    TristateTrue

    -1

    Opens as Unicode

    TristateFalse

    0

    Opens as ASCII

  • The path element of FileName can be relative or absolute.

  • The default IOMode setting is ForReading (1).

  • The default Format setting is ASCII ...

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